test

2006-02-10 Thread Bock
test comp.lang.python
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: installing python on a server?

2006-02-10 Thread Terry Hancock
On Fri, 10 Feb 2006 20:22:07 GMT
John Salerno <[EMAIL PROTECTED]> wrote:
> Can anyone tell me how complicated it might be to install
> Python on my  server so I can use it for web apps? Is it a
> one-time process, or  something to maintain?

Installing Python on a server is really, really easy.  At
least it is if you have root privileges and a reasonably
well-known platform to install on.

*USING* the Python installation for web applications is a
bit more complicated -- you have many choices about how to
do that.

For my money, the easy way if you are mostly wanting to make
web applications is to use Zope. It has a big up-front
learning curve, but once you get to know it, maintaining
scripts becomes trivially easy to do.

If you have other constraints on your server, or you really
just want a static site with a few dynamic elements, you
might be better served with a lighter-weight package than
Zope, and there's maybe a dozen different ones to choose
from.  Easier to learn, but probably more work in the long
run if you have to do a lot of script work on your site.

-- 
Terry Hancock ([EMAIL PROTECTED])
Anansi Spaceworks http://www.AnansiSpaceworks.com

-- 
http://mail.python.org/mailman/listinfo/python-list


"Is" is "is" [was: any way to customize the is operator?]

2006-02-10 Thread Steve Holden
Lonnie Princehouse wrote:
>>Why did you want to customize "is"?
> 
> 
> Well, mostly out of principle ;-)
> 
> But also because I'm wrapping a C library which passes around C structs
> which are wrapped in shim C++ classes for a Boost.Python layer.  Boost
> Python does a marvelous job of translating between Python and C++ data
> types; when a C structure is returned, it magically translates that
> structure into a Python wrapper.   The problem is that a _new_ Python
> wrapper is created every time a pointer is returned, even if a  wrapper
> already exists for that particular pointer.
> 
> To illustrate:  Suppose you have a function in C++ which is a simple
> identity function, e.g.
> 
> template 
> T *identity (T *x) {
> return x;
> }
> 
> Calling the wrapped version of this function from Python will produce a
> Python wrapper which represents the same underlying C++ object, but is
> not actually the same Python object:
> 
> 
b = identity(a)
b is a
> 
> False
> 
> I wanted to override the behavior of "is" so that (a is b) would be
> True --- which shouldn't have caused a problem, since the wrapper
> class's attributes are read-only from Python.  As it is, I've overriden
> __cmp__ and __hash__, so at least I get the correct dictionary behavior
> 
> 
mydict = { a : 'something' }
b = identity(a)
b in mydict
> 
> True
> 
> It's quite possible that there is some way to do this correctly from
> the Boost.Python side of things... my understanding of how to use
> Boost.Python is minimal.
> 
I will adopt my usual stance here of unequivocally stating that there is 
no way you can do what you want to. In the case of the "is" operator you 
can only expect truth when the left- and right-hand side operands refer 
to the same object.

This strategy is usually sound: typically, before the metaphorical ink 
has dried on my post some upstart comes along to prove me completely 
wrong. So, I have done about all I can to help you. It's up to the rest 
of the community now to prove me wrong (as they have so many times in 
the past :).

regards
  Steve

PS: I'm afraid I couldn't resisit shortening yur odds somewhat by doing 
what I usually fail to do and examining the source of is_() in 
Modules/operator.c. I'm afraid it's not looking good ... the result of 
"is" does appear to depend only on the memory addresses of the two 
operands being the same:

 result = (a1 == a2) ? Py_True : Py_False;
 Py_INCREF(result);

sorry ...
-- 
Steve Holden   +44 150 684 7255  +1 800 494 3119
Holden Web LLC www.holdenweb.com
PyCon TX 2006  www.python.org/pycon/

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Legality of using Fonts

2006-02-10 Thread Terry Hancock
On 10 Feb 2006 09:08:28 -0800
"Kamilche" <[EMAIL PROTECTED]> wrote:
> Let's say I own a font, and use it in a paint program to
> 'draw some text' on a picture that I slap up on the
> Internet. Everything's probably fine, right? But what if I
> draw some text on a bitmap on the hard drive, add drop
> shadows and decorations, and use it to 'blit' text in a
> game? The answer is less obvious to me then.

In fact, the answer depends on what country you are in.

In the United States, the actual visual images of the
characters in a font are not copyrightable material. You can
do anything you like with them.

TrueType, however, adds an extra wrinkle, because a TT font
is actually a *program* to create those images.  However,
you can escape this entirely if the only thing you use is
the *rendering* of the characters.  You could, for example,
create an entire *bitmap* font at a given font size, by
cutting and pasting output from a TT font.

Using the *name* of the font may be a bit stickier, because
it may well be trademarked (i.e. if you generated your
bitmap font from the FooBar(TM) TTF, you may not be able to
call your font FooBar, though you may get away with calling
it TooBar, or some such thing.  Certain fonts that have wide
use in the free-software community, such as the "Lucida"
series have had this problem.

So far, this is all good news for you.  But in fact, fonts
can be copyrightable under the laws of some nations, so you
could get into a sticky area just because of that.

I think that even in that case, though, you'd be okay with
just about any font you have a legal right to use.

So, I personally consider that reason enough to prefer free
fonts, and there are quite a few of them available. Many of
them are quite nice.  Unfortunately, of course, there is
*not* as much selection as would be nice, and it would be a
great thing if more free-licensed typography was available.
But it is, of course, hard and exacting work that not many
people know how to do well.

Finding truly free-licensed fonts can be a bit difficult
because there are so-many "sort of" free fonts that it
clutters the field.  Several good fonts are included in the
Debian Linux distribution, though, and of course, they had
to get debian-legal's stamp of approval to get there, so
they are indeed free.  Otherwise, you have to look harder,
and read carefully.

Cheers,
Terry

 -- 
Terry Hancock ([EMAIL PROTECTED])
Anansi Spaceworks http://www.AnansiSpaceworks.com

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: is there a better way?

2006-02-10 Thread Paul Rubin
"[EMAIL PROTECTED]" <[EMAIL PROTECTED]> writes:
> But this seems ugly to me, and using "while" give me the heebies.  Is
> there a better approach?

Note that "list" is the name of a built-in type; I used "mylist".
Alex Martelli described how to do it in log n time using the bisect
module.  Here's a dumb linear time method that might be faster for
small n (of course you should time the different methods for your
particular Python implementation, if the speed matters):

   del mylist[len(mylist) - mylist.count(0):]

The above an example of where the natural

   del mylist[-mylist.count(0):]

does totally the wrong thing if there are no 0's in the list.  There
was a huge thread a while back about ways to fix that.

Another way, might be faster, esp. there's more than a few 0's:

   try:
 del mylist[mylist.index(0)]
   except ValueError: 
 pass   # no 0's in the list
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: is there a better way?

2006-02-10 Thread Alex Martelli
[EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:

> Problem:
> 
> You have a list of unknown length, such as this: list =
> [X,X,X,O,O,O,O].  You want to extract all and only the X's.  You know
> the X's are all up front and you know that the item after the last X is
> an O, or that the list ends with an X.  There are never O's between
> X's.

If the list is incredibly long, you should use a bisection approach.
Standard module bisect in the Python library could help, but mostly as
an _example_, since it unfortunately relies on normal alphabetic order,
and alphabetically speaking X should come _after_ O, not _before_.

But the algorithm is still sound:

1. look at the midpoint.
2. if it's an X, so are all previous items -- recurse to second half
3. if it's an O, so are all following items -- recurse to first half

Getting all conditions exactly right is tricky (which is why bisect is a
good model!), but this way you get O(log N) performance for a list of
length N.

If N is not too huge, O(N) might be OK, and is, of course, way simpler
to code!-)


Alex
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Inserting record with Microsoft Access

2006-02-10 Thread Tim Roberts
"jeffhg582003" <[EMAIL PROTECTED]> wrote:
>
>I am developing a python script which add records to 
>a microsoft access tables. All my tables have autogenerated number
>fields. I am trying to capture the number generated from the insert but
>I am not exactly sure how to do that after an insert.

http://support.microsoft.com/kb/221931/EN-US/

What tool are you using?  With ADODB recordsets, you can fetch the
"absolutePosition" property, save it, do a Requery to update the recordset,
then set absolutePosition to the value you saved.  Now, you can read the
fields of your new record, including the autonumber.
-- 
- Tim Roberts, [EMAIL PROTECTED]
  Providenza & Boekelheide, Inc.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: by reference

2006-02-10 Thread Tim Roberts
"dirvine" <[EMAIL PROTECTED]> wrote:
>
>Thanks but I am a bit unsure as to what error I have made by posting
>this question. I am not trying to be funny but can you give me a
>pointer to the issue.

The problem is that your question is quite unclear.  I suggest that you
post your exact Python code, with the results you get, and the results you
expect.  That's usually enough!
-- 
- Tim Roberts, [EMAIL PROTECTED]
  Providenza & Boekelheide, Inc.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: installing python on a server?

2006-02-10 Thread John Salerno
Renato wrote:
> You mentioned using python for web apps: with which framework?
> (TurboGears, CherryPy, Subway, Django, whatever) Or only for cgi?
> 
> With which web server? (Apache, Twisted, Zope, etc.)
> 
> On which linux platform? (Slackware, Debian, Fedora/RedHat, Suse, etc)
> 
> I think you'll have to think about other questions before.
> 
> On systems with package management (pretty much all of them, except
> Slack) install is a matter of a few commands. And you can automate it,
> obviously.
> 

Yikes, that's all the stuff I don't know. Maybe this is over my head 
right now.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Scientific Computing with NumPy

2006-02-10 Thread Alex Martelli
David M. Cooke <[EMAIL PROTECTED]> wrote:

> "linda.s" <[EMAIL PROTECTED]> writes:
> 
> > where to download numpy for Python 2.3 in Mac?
> > Thanks!
> > Linda
> 
> I don't know if anybody's specifically compiled for 2.3; I think most
> of the developers on mac are using 2.4 :-)

However, what comes with MacOSX is STILL 2.3 (specifically 2.3.5 with
Tiger).


Alex
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Yet another GUI toolkit question...

2006-02-10 Thread Kevin Walzer
Dan Sommers wrote:
> On Fri, 10 Feb 2006 19:16:36 -0500,
> Kevin Walzer <[EMAIL PROTECTED]> wrote:
> 
>> For what it's worth, my application has to run on OS X and Windows,
>> and will be commercial, so this combination of requirements rules out
>> PyGTK/PyQt/just about every other cross-platform GUI toolkit.
> 
> According to their respective web sites, both Qt and PyQt have
> commercial licenses, and both run on both OS X and Windows.  Is there
> another reason you cannot use them?  Usually the concern is the other
> way around, that the Qt and PyQt licenses aren't sufficiently free or
> Free.
> 
> Disclaimer:  I have no financial or business ties to Trolltech or to
> Riverbank.
> 
> Regards,
> Dan
> 

Commercial Qt is a little out of my price range.

-- 
Kevin Walzer
iReveal: File Search Tool
http://www.wordtech-software.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Legality of using Fonts

2006-02-10 Thread Robert Kern
Ross Ridge wrote:
> Steven D'Aprano wrote:
> 
>>It is highly unlikely that any judge will be fooled by a mere change in
>>format ("but Your Honour, I converted the TTF file into a bitmap").
> 
> If that were true, almost the entire X11 bitmap font collection would
> be illegal.  Fonts aren't subject copyright, just the hints in most
> outline fonts, which are considered computer programs.

In the interest of adding some specifics:

  http://www.faqs.org/faqs/fonts-faq/part2/

-- 
Robert Kern
[EMAIL PROTECTED]

"In the fields of hell where the grass grows high
 Are the graves of dreams allowed to die."
  -- Richard Harter

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Legality of using Fonts

2006-02-10 Thread Ross Ridge
Steven D'Aprano wrote:
> It is highly unlikely that any judge will be fooled by a mere change in
> format ("but Your Honour, I converted the TTF file into a bitmap").

If that were true, almost the entire X11 bitmap font collection would
be illegal.  Fonts aren't subject copyright, just the hints in most
outline fonts, which are considered computer programs.

  Ross Ridge

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: functional 0.5 released

2006-02-10 Thread bonono

Collin Winter wrote:
> As always, feedback welcome!

Any specific reason flip only flip the first 2 arguments rather than
the whole tuple ?

That is, I would like to see:

assert(f(a,b,c, d) == flip(f)(d, c, b, a))

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Yet another GUI toolkit question...

2006-02-10 Thread Dan Sommers
On Fri, 10 Feb 2006 19:16:36 -0500,
Kevin Walzer <[EMAIL PROTECTED]> wrote:

> For what it's worth, my application has to run on OS X and Windows,
> and will be commercial, so this combination of requirements rules out
> PyGTK/PyQt/just about every other cross-platform GUI toolkit.

According to their respective web sites, both Qt and PyQt have
commercial licenses, and both run on both OS X and Windows.  Is there
another reason you cannot use them?  Usually the concern is the other
way around, that the Qt and PyQt licenses aren't sufficiently free or
Free.

Disclaimer:  I have no financial or business ties to Trolltech or to
Riverbank.

Regards,
Dan

-- 
Dan Sommers

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Socket Programming - Question

2006-02-10 Thread Grant Edwards
On 2006-02-11, D <[EMAIL PROTECTED]> wrote:

> I've used os.popen() before, but if I execute it on a remote
> system how could I get the output back to the requesting
> machine?

Write it to the socket?

-- 
Grant Edwards   grante Yow!  Where does it go when
  at   you flush?
   visi.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Jython inherit from Java class

2006-02-10 Thread Frank LaFond
Jython 2.2 Alpha 1 supports Java 1.5

Frank.

Kent Johnson wrote:
> Mark Fink wrote:
> 
>> I observed something strange when I tried to compile the jython class:
>> 'assert' is a keyword, and may not be used as an identifier
>> (try -source 1.3 or lower to use 'assert' as an identifier)
>> public static void assert(PyObject test, PyObject message) {
> 
> 
>> Looks like something in the Jython core causes the problem
>> (org\python\core\Py.java) any Ideas what I can do?
> 
> 
> I think jythonc is not compatible with Java 1.5, try compiling with 1.4.
> 
> Kent
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Socket Programming - Question

2006-02-10 Thread Paul Rubin
"[EMAIL PROTECTED]" <[EMAIL PROTECTED]> writes:
> I am relatively new to Python, and wanted to see if this is even
> possible, and if so how to go about implementing it.  What I'm looking
> to do is create a client/server application that does the following:
> 
> 1)  System2 listens on port > 1023
> 2)  System1 connects to System2 and sends traffic to it - based on the
> traffic it receives (i.e. a special string), System2 executes
> command-line commands and returns the output to System1.

You're asking how to write a TCP server in general.  You might look at
the SocketServer module in the standard library, which gives a
reasonable framework for that kind of server.  However, its
documentation is not very good.  Alex Martelli's "Python Cookbook" may
have some better examples.  

If you want your server to be able to handle multiple client sessions
simultaneously, use SocketServer.ThreadingMixin (for multiple threads)
or SocketServer.ForkingMixin (multiple processes).  Beware that this
stuff is not easy for beginners, unless you've had experience writing
servers in other languages (maybe Java).

There's another issue too, especially if your app is a virus scanner:
you have to think very hard about what happens if a malicious client
connects to your server (a virus scanning app is an unusually juicy
target for such attacks).  It's extremely easy to leave security holes
open (the viruses themselves typically exploit such holes in Windows)
so you have to develop a paranoid attitude about what kinds of things
the attacker can try and how you can defend.  Using Python puts you
one step ahead of Windows, since you're mostly immune to buffer
overflow bugs, a very common vulnerability.  But it's still an area
full of hazards and not so good for beginners.

This is good bedtime reading: http://www.dwheeler.com/secure-programs/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Socket Programming - Question

2006-02-10 Thread D
I've used os.popen() before, but if I execute it on a remote system how
could I get the output back to the requesting machine?

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Socket Programming - Question

2006-02-10 Thread D
Thanks!  Now, I'm a bit confused as to exactly how it works - will it
display the output of what it executes on the target system?  I would
like to create a window in Tktinker to where a user can select options
(such as run scan on remote system) - it would then run the
command-line based scan and return the output.  Does this sound like
something it would do?  Thanks again :)

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: absolute removal of '\n' and the like

2006-02-10 Thread S Borg
Steven,

 Thank you very much for your insights. They are quite helpful.

S

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: breaking from loop

2006-02-10 Thread George Sakkis
Using the (non-standard yet) path module
(http://www.jorendorff.com/articles/python/path/), your code can be
simplified to:

from path import path, copy

def copy_first_match(repository, filename, dest_dir):
try:
first_match = path(repository).walkfiles(filename).next()
except StopIteration:
return False
else:
copy(first_match, dest_dir)
return True


I/O exceptions are left to propagate to the caller.

George

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: equivalent functions?

2006-02-10 Thread wietse
Got it! Thanks for your time.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: equivalent functions?

2006-02-10 Thread wietse
Got it! Thanks for your time.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: equivalent functions?

2006-02-10 Thread Lonnie Princehouse
Very close... it is equivalent to:

apply_each = lambda fns, args=[]: [f(*args) for f in fns]

The asterisk in f(*args) expands the sequence to fill the arguments to
f, where as f(args) would pass the args as only the first argument to
the function.

apply is deprecated, replaced by the syntax:  function( *args,
**keywords )

-- 
http://mail.python.org/mailman/listinfo/python-list


equivalent functions?

2006-02-10 Thread wietse
Hello,

I'm reading "Text processing in Python" by David Mertz. In there he
defines a function

apply_each  = lambda fns, args=[]: map(apply, fns, [args]*len(fns))

I thought that this would be equivalent to:

apply_each = lambda fns, args=[]: [f(args) for f in fns]

Can anybody confirm this? If not, how are they different?
Thanks,
Wietse

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Scientific Computing with NumPy

2006-02-10 Thread David M. Cooke
"linda.s" <[EMAIL PROTECTED]> writes:

> where to download numpy for Python 2.3 in Mac?
> Thanks!
> Linda

I don't know if anybody's specifically compiled for 2.3; I think most
of the developers on mac are using 2.4 :-)

But (assuming you have the developer tools installed) it's really to
compile: python setup.py build && python setup.py install.

Do you need Tiger (10.4) or Panther (10.3) compatibility?

-- 
|>|\/|<
/--\
|David M. Cooke
|cookedm(at)physics(dot)mcmaster(dot)ca
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Socket Programming - Question

2006-02-10 Thread Grant Edwards
On 2006-02-11, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:

> I am relatively new to Python, and wanted to see if this is
> even possible, and if so how to go about implementing it.
> What I'm looking to do is create a client/server application
> that does the following:
>
> 1)  System2 listens on port > 1023
> 2)  System1 connects to System2 and sends traffic to it - based on the
> traffic it receives (i.e. a special string), System2 executes
> command-line commands and returns the output to System1.

Sure.  Just use os.popen() or one of it's relatives to execute
the program:

http://www.python.org/doc/current/lib/os-newstreams.html#os-newstreams

-- 
Grant Edwards   grante Yow!  I'm not available
  at   for comment...
   visi.com
-- 
http://mail.python.org/mailman/listinfo/python-list


PySizeof: almost useful

2006-02-10 Thread Ian Leitch
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

Hi list,

I'm writing a little module to calculate the size of given objects, I
just need a few little pointers to get the thing into a useful shape.

Code here: http://dev.gentoo.org/~port001/Code/PySizeof/

The points I'm confused about are:

1. My method of determining the malloc() overhead is probably laughable,
what's the correct method?

2. I'm at a loss as how to calculate the size of a long object -- any tips?

3. How much memory do instance, module and instancemethod objects hold?
You'll notice I'm getting the size of most objects internal structures,
what structures' size should I be measuring for such objects?

4. When calculating the size of a dict, if it contains more than the
initial ma_smalltable size (8) should I be subtracting 8 from the len()
number multiplied with the size of a dict entry? See line 73 in pysizeof.py

No doubt there are some other glaring mistakes :)

Many thanks to anyone bored enough to review this code.

- -- Ian
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.1 (GNU/Linux)

iD8DBQFD7S6XefZ4eWAXRGIRAre2AJ4nf//qF/O9B+IhVgdQOj+1rLePZwCaAhvH
7FoGfjjhlm4bH4ZoQY+b+SA=
=C3np
-END PGP SIGNATURE-
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Socket Programming - Question

2006-02-10 Thread [EMAIL PROTECTED]
[EMAIL PROTECTED] wrote:

> An example of what I am looking to use this for is for remote virus
> scanning.  So System2 listens, System1 connects and sends it the

Just found this through OSNews:
http://rpyc.sourceforge.net/

It actually seems to be a perfect fit for your job.

Lorenzo

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Legality of using Fonts

2006-02-10 Thread Kamilche
Yeah, that's what I'm thinking, as well. Showing all the text on an
image is one thing... using that image as the basis of a font engine is
something different.

Luckily, someone has sent me a link to a set of free TrueType fonts -
http://www.gnome.org/fonts , the 'Vera' family. I guess I'll turn those
into bitmaps to stay out of the gray area.

I have other reasons I want to use a bitmap font, other than licensing
issues.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: is there a better way?

2006-02-10 Thread Dave Hansen
On Sat, 11 Feb 2006 01:37:59 +0100 in comp.lang.python, Schüle Daniel
<[EMAIL PROTECTED]> wrote:

>Lonnie Princehouse wrote:
>> everybody is making this way more complicated than it needs to be.
>> 
>> storage = list[:list.index(O)]
>
>the question is whether the old list is needed in the future or not
>if not then it would be easer/mor efficient to use
>
>del lst[lst.index(0):]

And you're both forgetting the list can end with X.  the index method
raises a ValueError exception if the desired value is not found in the
list.  Assuming you want to keep the original list and create a new
list called storage, you could try

   if lst[-1] == X:
  storage = lst[:]
   else:
  storage = lst[:lst.index(O)]

or even

   try:
  storage = lst[:lst.index(O)]
   except ValueError:
  storage = lst[:]

(WARNING: untested!)

Regards,


   
-=Dave

-- 
Change is inevitable, progress is not.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: arrays in python

2006-02-10 Thread plahey
> Oh, don't tell me, I love playing guessing games!

Don't you mean "No no... don't tell me. I'm keen to guess."

Sorry, I couldn't resist... :-)

(for those who just went huh?, see
http://www.aldo.com/sgt/CheeseShoppeSkit.htm)

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: any way to customize the is operator?

2006-02-10 Thread Lonnie Princehouse
> Why did you want to customize "is"?

Well, mostly out of principle ;-)

But also because I'm wrapping a C library which passes around C structs
which are wrapped in shim C++ classes for a Boost.Python layer.  Boost
Python does a marvelous job of translating between Python and C++ data
types; when a C structure is returned, it magically translates that
structure into a Python wrapper.   The problem is that a _new_ Python
wrapper is created every time a pointer is returned, even if a  wrapper
already exists for that particular pointer.

To illustrate:  Suppose you have a function in C++ which is a simple
identity function, e.g.

template 
T *identity (T *x) {
return x;
}

Calling the wrapped version of this function from Python will produce a
Python wrapper which represents the same underlying C++ object, but is
not actually the same Python object:

>>> b = identity(a)
>>> b is a
False

I wanted to override the behavior of "is" so that (a is b) would be
True --- which shouldn't have caused a problem, since the wrapper
class's attributes are read-only from Python.  As it is, I've overriden
__cmp__ and __hash__, so at least I get the correct dictionary behavior

>>> mydict = { a : 'something' }
>>> b = identity(a)
>>> b in mydict
True

It's quite possible that there is some way to do this correctly from
the Boost.Python side of things... my understanding of how to use
Boost.Python is minimal.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: absolute removal of '\n' and the like

2006-02-10 Thread Steven D'Aprano
On Fri, 10 Feb 2006 15:21:58 -0800, S Borg wrote:

> Hello,
> 
>  If I have a string, what is the strongest way to assure the
> removal of any line break characters?

What do you mean "strongest"? Fastest, most memory efficient, least lines
of code, most lines of code, least bugs, or just a vague "best"?


> Line break characters must always be the last character in a line, 

Must they? Are you sure? What happens if the file you are reading from
doesn't end with a blank line?


> so would this:str = linestring[:-1]
>  work?

Using the name of a built-in function (like str) is called shadowing. It
is a BAD idea. Once you do that, your code can no longer call the built-in
function.

s = line[:-1] will work if you absolutely know for sure the line ends with
a newline.

This would be safer, if you aren't sure:

if line[-1] == '\n':
s = line[:-1]
else:
s = line

but that assumes that line is a non-empty string. If you aren't sure about
that either, this is safer still:

if line and line[-1] == '\n':
s = line[:-1]
else:
s = line

If you want to clear all whitespace from the end of the line, not just
newline, this is better still because you don't have to do any tests:

s = line.rstrip()

There is also a lstrip to strip leading whitespace, and strip() to strip
both leading and trailing whitespace.



-- 
Steven.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: arrays in python

2006-02-10 Thread Steven D'Aprano
On Fri, 10 Feb 2006 17:50:21 -0500, Kermit Rose wrote:

> I want to write a program in python using integer arrays.
>  
> I wish to calculate formulas using 200 digit integers.

Must the integers have exactly 200 digits? If you multiply one of these
200-digit integers by ten, should it silently overflow, raise an
exception, or become a 201-digit integer?

[snip]

> The zeros function always gives me an error message.

Oh, don't tell me, I love playing guessing games!

Is it a SyntaxError?



-- 
Steven.

-- 
http://mail.python.org/mailman/listinfo/python-list


Yet another GUI toolkit question...

2006-02-10 Thread Kevin Walzer
...with a twist.

I'm undertaking my first semi-substantial Python GUI application after a
long time dabbling with the language.

I'm fairly experienced with Tcl/Tk, so Tkinter seems the obvious choice
to reduce my Python learning curve. However, my Tcl applications
typically make use of a *lot* of extensions to the core widget set, such
as BWidgets, tablelist, and Tile.

I've found minimal Tkinter wrappers for all of these extensions, but
they are all labelled "experimental," lightly documented at best, and
little-used (as far as I can tell) by Python developers.

So: my question is, would it be more productive for me to wrestle with
these extensions when there doesn't seem to be much constituency for
their use, or would it be better/faster/more efficient for me to start
scaling the wxPython mountain?

For what it's worth, my application has to run on OS X and Windows, and
will be commercial, so this combination of requirements rules out
PyGTK/PyQt/just about every other cross-platform GUI toolkit.

Advice, especially from those Tkinter devs who look beyond the core
widget set for their apps, is appreciated!

-- 
Kevin Walzer
iReveal: File Search Tool
http://www.wordtech-software.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: cmd

2006-02-10 Thread Steven D'Aprano
On Sat, 11 Feb 2006 00:47:14 +0100, Gerber wrote:

> I'd like some documentation on the cmd module, besides the regular
> docs, in help() and docs.python.org...

Is this a trick question? You'd like some documentation apart from the
documentation?

Have you tried reading the source code to the module? Have you tried
googling? Have you tried using Python's extensive introspection
capabilities on the module?

Failing that, do you have a specific question you would like to ask?


-- 
Steven.

-- 
http://mail.python.org/mailman/listinfo/python-list


Socket Programming - Question

2006-02-10 Thread [EMAIL PROTECTED]
I am relatively new to Python, and wanted to see if this is even
possible, and if so how to go about implementing it.  What I'm looking
to do is create a client/server application that does the following:

1)  System2 listens on port > 1023
2)  System1 connects to System2 and sends traffic to it - based on the
traffic it receives (i.e. a special string), System2 executes
command-line commands and returns the output to System1.

An example of what I am looking to use this for is for remote virus
scanning.  So System2 listens, System1 connects and sends it the
traffic to start the scan, then System1 returns either what would be
listed in the Command Prompt window, or possibly the contents of the
logfile.

Any help would be greatly appreciated!

Doug

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: absolute removal of '\n' and the like

2006-02-10 Thread S Borg


Russ,

 Thanks a ton for ending a 3 day headache.

S

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: module with __call__ defined is not callable?

2006-02-10 Thread Bengt Richter
On Thu, 9 Feb 2006 10:07:49 +1100, "Delaney, Timothy (Tim)" <[EMAIL PROTECTED]> 
wrote:

>Steven D'Aprano wrote:
>
>> That's not a _reason_, it is just a (re-)statement of fact. We know
>> that defining a __call__ method on a module doesn't make it callable.
>> Why not? The answer isn't "because defining a __call__ method on a
>> module or an instance doesn't make it callable", that's just avoiding
>> the question.=20
>
>My reading of the OP sounded like he wanted to know the *technical*
>reason for why it doesn't work - which is what I provided.
>
>If you can come up with a convincing argument, after re-reading the OP
>(as I've just done), that that is *not* what he meant, I'm all ears.
>
While you can't put __call__ on the builtin module type,
you _can_ put it on a subclass:

 >>> class M(type(__builtins__)):
 ...def __call__(self): return '%r was called'%self
 ...
 >>> m = M('M')
 >>> m()
 " was called"

Not that I can see why the OP would want to spell any module access module().

OTOH, I could see wanting to define properties, and access module.latest_foo
and have it choose dynamically from versioned stuff, or something like that.
Of course you can write module.get_latest_foo() as an ordinary function, and
not be bothered with subclassing and jimmying sys.modules and such.

Properties and methods are both forms of descriptors, so they need to be 
attributes
of the type to work. With a subclass you could do that too.

Regards,
Bengt Richter
-- 
http://mail.python.org/mailman/listinfo/python-list


installing matplotlib in cygwin

2006-02-10 Thread nashmeister
has anyone had any success compiling matplotlib in cygwin?  i had some
rebasing problems that i got around, but when i finally got everything
to install without any complaints and did "import pylab" i got dumped
out of python altogether without any errors.

some thing i did:
cd  /usr/lib
ln -s libtk84.a libtk8.4.a
ln -s libtcl84.a libtcl8.4.a
cd /
find /usr/lib/python2.2/site-packages -name "*.dll" >
/etc/setup/python-site-packages.lst
(remove all initial slashes)
gzip /etc/setup/python-site-packages.lst

(exit all cygwin and 'rebaseall')
cd /tmp
tar xzvf matplotlib-0.86.2.tar.gz
cd matplotlib-0.86.2
(edit matplotlibrc)
(change to "backend:TkAgg" and "numerix:numpy")
(edit setup.py)
(change to 'backend':'TkAgg' and 'numerix':'numpy')
(change to "BUILD_GTKAGG = False")
(change to "BUILD_GTK = False")
(change to "BUILD_TKAGG = True")
python setup.py build
python setup.py install

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: is there a better way?

2006-02-10 Thread Scott David Daniels
Scott David Daniels wrote:
> [EMAIL PROTECTED] wrote:
>> Problem:
>>
>> You have a list of unknown length, such as this: list =
>> [X,X,X,O,O,O,O].  You want to extract all and only the X's.  You know
>> the X's are all up front and you know that the item after the last X is
>> an O, or that the list ends with an X.  There are never O's between
>> X's.
>>
>> I have been using something like this:
>> while list[0] != O:
>> storage.append(list[0])
>> list.pop(0)
>> if len(list) == 0:
>> break
>> But this seems ugly to me, and using "while" give me the heebies.  Is
>> there a better approach?
>>
> 
> Your names could be better as someone mentioned.
> ex, oh = 7, 13   # for example
> data = [ex, ex, ex, oh, oh, oh, oh]
> If you need a list distinct from the original:
> try:
> result = data[: data.index(oh)]
> except ValueError:
> result = list(data)
> 
> Or you could simply:
> try:
> data = data[: data.index(oh)]
> except ValueError:
> pass
> and data will be either the sublist you want or the original list.

I forgot the obvious:

 result = data.count(ex) * [ex]

-- 
-Scott David Daniels
[EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: ordered sets operations on lists..

2006-02-10 Thread bonono

Raymond Hettinger wrote:
> The intersection step is unnecessary, so the answer can be simplified a
> bit:
>
> >>> filter(set(l2).__contains__, l1)
> [5, 3]
> >>> filter(set(l1).__contains__, l2)
> [3, 5]

stand corrected.

-- 
http://mail.python.org/mailman/listinfo/python-list


cmd

2006-02-10 Thread Gerber
I'd like some documentation on the cmd module, besides the regular
docs, in help() and docs.python.org...

Gerber
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: read-only attributes

2006-02-10 Thread john peter
Thank you for the suggestion!bruno at modulix <[EMAIL PROTECTED]> wrote:  limodou wrote:> On 2/10/06, john peter  wrote:(snip)>> what do i have to do if i want my application code to have>>read-only>> attributes?>>> I think you may consider property() built-in function:> > property( [fget[, fset[, fdel[, doc)> > Return a property attribute for new-style classes (classes that derive> from object).> fget is a functions/function/callable/> for getting an attribute value, likewise fset is a> function for setting, and fdel a function for del'ing, an attribute.> Typical use is to define a managed attribute x:> > > class C(object):&g!
 t;
 def __init__(self): self.__x = None> def getx(self): return self.__x> def setx(self, value): self.__x = value> def delx(self): del self.__x> x = property(getx, setx, delx, "I'm the 'x' property.")Note that you don't need to define all three accessors. For a'read-only' attribute, just define the getter:class ReadOnly(object):   def __init__(self, x):  self._x = x   x = property(fget=lambda self: self._x)-- bruno desthuillierspython -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) forp in '[EMAIL PROTECTED]'.split('@')])"-- http://mail.python.org/mailman/listinfo/python-list
		 Yahoo! Mail 
Use Photomail to share photos without annoying attachments.-- 
http://mail.python.org/mailman/listinfo/python-list

Re: installing python on a server?

2006-02-10 Thread 3c273
"Renato" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
-snip-
> On systems with package management (pretty much all of them, except
> Slack) install is a matter of a few commands. And you can automate it,
> obviously.

Slackware has package management, (pkgtool, installpkg, removepkg,
upgradepkg), it just doesn't do dependency checking.
http://www.slackbook.org/html/package-management.html
Louis


-- 
http://mail.python.org/mailman/listinfo/python-list


Re: arrays in python

2006-02-10 Thread Schüle Daniel
> I want to write a program in python using integer arrays.

you can :)


> I wish to calculate formulas using 200 digit integers.

no problem

> I could not find any documentation in python manual about declaring arrays.
>  
> I searched the internet

read here
http://diveintopython.org/native_data_types/lists.html

maybe list are what you are looking for

> and found an example that said I must declare
>  
> from Numeric import *

yes, one can use Numeric for this taks too

> and I downloaded a numerical python  extension,
>  
> but still  have not found a way to declare an array of given length.
>  
> The zeros function always gives me an error message.

 >>> import Numeric as N, random as rand
 >>> nums = [33 ** rand.randint(10,100) for i in range(200)]
 >>> len(nums)
200
 >>> nums[0]
1666465812864030391541732975677083441749008906546726522024522041932256405404932170047036994592860856233379702595619607481259213235163454890913L
 >>>
 >>> a = N.array(nums)
 >>> len(a)
200
 >>> a[0]
1666465812864030391541732975677083441749008906546726522024522041932256405404932170047036994592860856233379702595619607481259213235163454890913L
 >>>


by the way, you know you can use interactive Python iterpreter
and there is dir and help function

 >>> dir(a)
['__copy__', '__deepcopy__', 'astype', 'byteswapped', 'copy', 
'iscontiguous', 'itemsize', 'resize', 'savespace', 'spacesaver', 
'tolist', 'toscalar', 'tostring', 'typecode']
 >>> dir(nums)
['__add__', '__class__', '__contains__', '__delattr__', '__delitem__', 
'__delslice__', '__doc__', '__eq__', '__ge__', '__getattribute__', 
'__getitem__', '__getslice__', '__gt__', '__hash__', '__iadd__', 
'__imul__', '__init__', '__iter__', '__le__', '__len__', '__lt__', 
'__mul__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', 
'__repr__', '__reversed__', '__rmul__', '__setattr__', '__setitem__', 
'__setslice__', '__str__', 'append', 'count', 'extend', 'index', 
'insert', 'pop', 'remove', 'reverse', 'sort']
 >>>

Regards, Daniel

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: absolute removal of '\n' and the like

2006-02-10 Thread Russell Blau

"S Borg" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
>  If I have a string, what is the strongest way to assure the
> removal of any line break characters?
>
> Line break characters must always be the last character in a line, so
> would
> this:str = linestring[:-1]
>
>  work?

Er, yes, if you don't mind (a) mangling any string that *doesn't* have a
newline as the last character, and (b) messing up any subsequent part of
your program that tries to use the built-in str() function (because you just
reassigned that name to something else).

I'd suggest:

foo = linestring.rstrip("\n")

You can also add to the quoted string any other characters you want to have
stripped; for example,

foo = linestring.rstrip("\n\r\t")

Or if you want to strip off *all* whitespace characters, just leave it out:

foo = linestring.rstrip()

Russ




-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Legality of using Fonts

2006-02-10 Thread Steven D'Aprano
On Fri, 10 Feb 2006 09:08:28 -0800, Kamilche wrote:

> I have a question for all you Pythoneers out there. I'm making a game
> with Python, and have a need for fonts. I am currently using a free
> TrueType font, but am considering switching to a bitmap font instead.
> 
> Let's say I own a font, and use it in a paint program to 'draw some
> text' on a picture that I slap up on the Internet. Everything's
> probably fine, right? But what if I draw some text on a bitmap on the
> hard drive, add drop shadows and decorations, and use it to 'blit' text
> in a game? The answer is less obvious to me then.
> 
> Any advice you could offer would be greatly appreciated!

Free legal advice you get from non-lawyers on Usenet is worth 10% of what
you paid for it.

But generally speaking, for what it is worth (10% of nothing), you can
distribute *images* you design which happen to incorporate text from a
font, but you cannot distribute the font itself UNLESS the font is
provided under a licence which explicitly permits you to re-distribute it.

It is highly unlikely that any judge will be fooled by a mere change in
format ("but Your Honour, I converted the TTF file into a bitmap"). Adding
decorations and such merely means you have created a derivative work of
the font, which the licence may not permit.

I suggest that you use a font which comes under a clearly free to
distribute licence, or you design your own.


-- 
Steven.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: appending to a list via properties

2006-02-10 Thread Larry Bates
Lonnie Princehouse wrote:
> Here's a curious hack I want to put up for discussion.  I'm thinking of
> writing a PEP for it.
> 
> Observation
> -
> I found myself using this construct for assembling multiple lists:
> 
> foo = []
> qux = []
> 
> while some_condition:
>a, b = calculate_something()
>foo.append(a)
>qux.append(b)
> 
> Not elegant!  It requires temporary variables a and b, which are only
> used to populate the lists.
> 
> 
> Suggestion
> 
> 
> class better_list (list):
> tail = property(None, list.append)
> 
> foo = better_list()
> qux = better_list()
> 
> while some_condition:
> foo.tail, qux.tail = calculate_something()
> 
> Granted, the name tail might not be the best, but you get the idea.
> 
> 
> Alternatives
> --
> 
> 1. Use "append" instead, preserving original list.append behavior.
> 
> class better_list (list):
> append = property(lambda l: lambda x: list.append(l,x),
> list.append)
> 
> 2. Use an external wrapper, similar to operator.*getter
> 
> class propertize (object):
> def __init__(self, target):
> self.__target__ = target
> def __setattr__(self, attribute, value):
> if attribute.startswith('_'): return
> object.__setattr__(self, attribute, value)
> else: getattr(self.__target__, attribute)(value)
> 
> propertize(foo).append, propertize(qux).append =
> calculate_something()
> 
>
> Well?
> 
Not entirely sure I understand, but here goes.  I normally
use list comprehensions.  I'm assuming that calculate_something()
is acting on a list of items.  If not then maybe some underlying
data refactoring is in order.  If so you write:

results=[calculate_something(x) for x in list_of_items]
foo=result[x[0] for x in results]
qux=result[x[1] for x in results]

Without knowing more about what calculate_something() does
and what condition terminates the loop it is hard to say if
this will work for you.

-Larry Bates
-- 
http://mail.python.org/mailman/listinfo/python-list


absolute removal of '\n' and the like

2006-02-10 Thread S Borg

Hello,

 If I have a string, what is the strongest way to assure the
removal of any line break characters?

Line break characters must always be the last character in a line, so
would
this:str = linestring[:-1]

 work?

This is my first real 'learning python' project, and I don't want to
get in the habit
of doing things the 'Java way'. Your comments and suggestions are very
much
appreciated.

thanks,

S

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: arrays in python

2006-02-10 Thread Steve Holden
Kermit Rose wrote:
> From: Kermit Rose
> Date: 02/10/06 17:36:34
> To: [EMAIL PROTECTED]
> Subject: Arrays
>  
>   
> Hello.
>  
> I want to write a program in python using integer arrays.
>  
> I wish to calculate formulas using 200 digit integers.
>  
> I could not find any documentation in python manual about declaring arrays.
>  
> I searched the internet
>  
> and found an example that said I must declare
>  
> from Numeric import *
>  
>  
> and I downloaded a numerical python  extension,
>  
> but still  have not found a way to declare an array of given length.
>  
> The zeros function always gives me an error message.
>  

No need to do anything special. Python allows long integers, and you can 
calculate directly with them:

  >>> big1 = int('1' + 100*'2')
  >>> big2 = int('2' + 100*'3')
  >>> big1
1222
2L
  >>> big2
2333
3L
  >>> big1 + big2
3555
5L
  >>>

regards
  Steve
-- 
Steve Holden   +44 150 684 7255  +1 800 494 3119
Holden Web LLC www.holdenweb.com
PyCon TX 2006  www.python.org/pycon/

-- 
http://mail.python.org/mailman/listinfo/python-list


arrays in python

2006-02-10 Thread Kermit Rose
From: Kermit Rose
Date: 02/10/06 17:36:34
To: [EMAIL PROTECTED]
Subject: Arrays
 
  
Hello.
 
I want to write a program in python using integer arrays.
 
I wish to calculate formulas using 200 digit integers.
 
I could not find any documentation in python manual about declaring arrays.
 
I searched the internet
 
and found an example that said I must declare
 
from Numeric import *
 
 
and I downloaded a numerical python  extension,
 
but still  have not found a way to declare an array of given length.
 
The zeros function always gives me an error message.
 
 
Kermit   <[EMAIL PROTECTED] >
 
 
 
 

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Daemon terminates unexpected

2006-02-10 Thread Steve Horsley
Incorporating Fredrik's fix (I learned something new reading 
that), try using an endless loop even if there is an exception 
like this:

 def run(self):
 while True:
 try:
 
 
 time.sleep(60) # wait, avoid spinning

so that even if there is an exception, it'll get up and go again.

Steve
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: installing python on a server?

2006-02-10 Thread Rene Pijlman
John Salerno:
>Hmm, sounds easy, yet I don't know where to start. 

try:
browser.browse(http://www.python.org/download/)
package = download(yourPlatform)
package.unpack()
exec(README.read())
except:
post specifics

-- 
René Pijlman
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: * 'struct-like' list *

2006-02-10 Thread Bengt Richter
On Tue, 07 Feb 2006 18:10:05 GMT, [EMAIL PROTECTED] (Bengt Richter) wrote:
[...]
>< ernesto.py >-
[...]
Just noticed:
>substrings = line.split()
>if substrings and isinstance(substrings, list) and substrings[0] == 
> 'Name:':
   --not needed

str.split always returns a list, even if it's length 1, so that was harmless 
but should be

 if substrings and substrings[0] == 'Name:':

(the first term is needed because ''.split() => [], to avoid [][0])
Sorry.

Regards,
Bengt Richter
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: installing python on a server?

2006-02-10 Thread Renato
You mentioned using python for web apps: with which framework?
(TurboGears, CherryPy, Subway, Django, whatever) Or only for cgi?

With which web server? (Apache, Twisted, Zope, etc.)

On which linux platform? (Slackware, Debian, Fedora/RedHat, Suse, etc)

I think you'll have to think about other questions before.

On systems with package management (pretty much all of them, except
Slack) install is a matter of a few commands. And you can automate it,
obviously.

-- 
bye,
Renato

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Question about idioms for clearing a list

2006-02-10 Thread Bryan Olson
Magnus Lycka wrote:
> Bryan Olson wrote:
> 
>> Magnus Lycka wrote:
>>
>>> Bryan Olson wrote:
>>>
 big_union = set()
 for collection in some_iter:
 big_union.update(t)
 collection.clear()
>>>
>>>
>>> I don't understand the second one. Where did 't' come from?
>>
>>
>> Cut-and-past carelessness. Meant to update with 'collection'.
> 
> 
> If some_iter gives you dicts, the code above will throw away
> your values,  and put the set of keys in big_union. Is that what
> you meant to do?

It can be quite useful. Python only recently added the set
type. Previously, the usual way to implement sets with
efficient membership testing was to use a dict where the
keys map to some irrelevant value. The above will work for
the old technique as well as for the set type.


 > I suspect most people would find this somewhat
> surprising. For sets and "BryanLists" it will put a set of all
> the contents of those collections in big_union.

That was the description: moving everything from several
collections into a single union.


> I think this
> just verifies my previous arguments. It's rarely meaningful to
> write functions that are meaingful for all builtin collections.

That's a nonsense argument, polymorphism doesn't have to work
over every type to be useful. Functions meaningful for either
sets or lists are common; that's enough justification for
giving corresponding operations the same interface.


-- 
--Bryan
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: is there a better way?

2006-02-10 Thread Schüle Daniel
I don't want to hijack the thread I was thinking
whether something like lst.remove(item = 0, all = True)
would be worth adding to Python?

it could have this signature

def remove(item, nItems = 1, all = False)
...
return how_many_deleted

lst.remove(item = 0, nItems = 1)
lst.remove(item = 0, nItems = 2)

lst.remove(item = 0, all = True)
in last case nItems is ignored

Regards, Daniel

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: in over my head ascii

2006-02-10 Thread Blair P. Houghton

[EMAIL PROTECTED] wrote:

> so. how do i make 200 occupy 4 bytes ?

Did you double-check that they didn't want "0200" in ascii
in the message?

As in:

STX0200ENX

Because that's always possible.  And, if you're _lucky_, they designed
the innards of the message so that "ENX" can never appear at random.
Though with a length parameter, you shouldn't have to worry about
that...though with a length parameter the ENX is redundant...

Argh!

I'm having flashbacks.

--Blair

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: how to kill a python process?

2006-02-10 Thread Steve Horsley
MackS wrote:
> Hello!
> 
> This question does not concern programming in python, but how to manage
> python processes. Is there a way to "name" a python process? At least
> on Linux, if I have two python programs running, they both run under
> the name "python"
> 
> #pidof program1.py
> [empty line]
> #pidof program1.py
> [empty line]
> # pidof python
> 1249 854
> 
> Is there a way to make them run under their own names, e.g., to make it
> easier to kill them by name using killall? Or am I stuck with
> registering the pid of each python process I create and then refer to
> that list whenever I need to selectively stop one of them? The latter
> makes managing a long list of processes very cumbersome...
> 
> Thanks for any help!
> 
> Mack
> 

I ran a script called test, and found this in my process list 
(sorry, the emailer wraps it):

steve14513 14452  0 21:43 pts/200:00:00 /usr/bin/python 
./test

But I also find that "killall test" kills it. So you don't need 
"killall python" at all.

HTH
Steve

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: is there a better way?

2006-02-10 Thread Schüle Daniel
Lonnie Princehouse wrote:
> everybody is making this way more complicated than it needs to be.
> 
> storage = list[:list.index(O)]

the question is whether the old list is needed in the future or not
if not then it would be easer/mor efficient to use

del lst[lst.index(0):]

Regards, Daniel

-- 
http://mail.python.org/mailman/listinfo/python-list


two generators working in tandem

2006-02-10 Thread john peter
I'd like to write two generators: one is a min to max sequence number generator that  rolls over to min again once the max is reached. the other is a generator that cycles  through N (say, 12) labels. currently, i'm using these generators in nested loops like  this:     seq_numbers = genSeqNum(min,max)  for label in genLabel():     for some_date in genDate(init):    for i in xrange(0, LIMIT):   print label, some_date, i, seq_numbers.next()     The problem I'm trying to solve is this:  when the seq_numbers generator rolls over, the label generator must be advanced  to the next one "in tandem". does anyone has any suggestion? thanks for any hepl!
		 Yahoo! Mail 
Use Photomail to share photos without annoying attachments.-- 
http://mail.python.org/mailman/listinfo/python-list

Re: is there a better way?

2006-02-10 Thread Jeremy Dillworth
You could eliminate a few lines like this:

-
while list and list[0] != O:
storage.append(list.pop(0))
-

Adding the "list and " to the front of the logic test will catch when
there are 0 elements, so the "if..break" lines are not needed.  Also
pop() returns the element popped, so there's no need for a separate
"list[0]" and "list.pop(0)"

You could also do the whole thing as a list comprehension (assuming
storage is a list, otherwise += may or may not work):
-
storage += [i for i in list if i == X]
-

But this is less efficient, since it will loop through all the O's too.
 The other solution stops at the first O.  This will also break if
there are any X's mixed with O's, though you've said that's not
currently the case, things can always change.

Lastly, you could do this:
-
list.append(O)
storage += list[:list.index(O)]
-

The first line makes sure there is always an O in list, otherwise
index(O) will throw an exception.  That's slightly ugly, but I still
like this solution, myself.

hope this helps,

Jeremy

-- 
http://mail.python.org/mailman/listinfo/python-list


appending to a list via properties

2006-02-10 Thread Lonnie Princehouse
Here's a curious hack I want to put up for discussion.  I'm thinking of
writing a PEP for it.

Observation
-
I found myself using this construct for assembling multiple lists:

foo = []
qux = []

while some_condition:
   a, b = calculate_something()
   foo.append(a)
   qux.append(b)

Not elegant!  It requires temporary variables a and b, which are only
used to populate the lists.


Suggestion


class better_list (list):
tail = property(None, list.append)

foo = better_list()
qux = better_list()

while some_condition:
foo.tail, qux.tail = calculate_something()

Granted, the name tail might not be the best, but you get the idea.


Alternatives
--

1. Use "append" instead, preserving original list.append behavior.

class better_list (list):
append = property(lambda l: lambda x: list.append(l,x),
list.append)

2. Use an external wrapper, similar to operator.*getter

class propertize (object):
def __init__(self, target):
self.__target__ = target
def __setattr__(self, attribute, value):
if attribute.startswith('_'): return
object.__setattr__(self, attribute, value)
else: getattr(self.__target__, attribute)(value)

propertize(foo).append, propertize(qux).append =
calculate_something()

   
Well?

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: installing python on a server?

2006-02-10 Thread John Salerno
Rene Pijlman wrote:
> John Salerno:
>> Can anyone tell me how complicated it might be to install Python on my 
>> server so I can use it for web apps?
> 
> 2 on a scale from 1 to 10.
> 
>> Is it a one-time process, or something to maintain?
> 
> Both :-)
> 
> I installed Python 2.2 - 2.4 from source on Linux with no problem
> whatsoever. I now plan about 5 minutes installation time per new release,
> that's 2 minutes to make coffee, 2 minutes to skim the release notes and
> README and 1 minute to watch ./configure; make; make install do it's
> magic.
> 
> There are some details to watch out for, such as having the required
> libraries and include files around before installation, to enable specific
> functionality (e.g. SSL support in socket). But that's no big deal.
> 

Hmm, sounds easy, yet I don't know where to start. What do I actually 
use to install it onto the server? I've never dealt with server stuff 
before, so I might not be familiar with the terminology.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: installing python on a server?

2006-02-10 Thread Rene Pijlman
John Salerno:
>Can anyone tell me how complicated it might be to install Python on my 
>server so I can use it for web apps?

2 on a scale from 1 to 10.

>Is it a one-time process, or something to maintain?

Both :-)

I installed Python 2.2 - 2.4 from source on Linux with no problem
whatsoever. I now plan about 5 minutes installation time per new release,
that's 2 minutes to make coffee, 2 minutes to skim the release notes and
README and 1 minute to watch ./configure; make; make install do it's
magic.

There are some details to watch out for, such as having the required
libraries and include files around before installation, to enable specific
functionality (e.g. SSL support in socket). But that's no big deal.

-- 
René Pijlman
-- 
http://mail.python.org/mailman/listinfo/python-list


installing python on a server?

2006-02-10 Thread John Salerno
Can anyone tell me how complicated it might be to install Python on my 
server so I can use it for web apps? Is it a one-time process, or 
something to maintain?

Thanks.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Replacing curses

2006-02-10 Thread Ian Ward
Ross Ridge wrote:
> In general it's impossible to know how many display positions some
> random Unicode character might use.  For example, Chinese characters
> normally take two display positions, but the terminal your using might
> not support them and display a single width replacement character.
> Hopefully, you're limitted in the character set you actually need to
> support and the terminals that your applicaiton will be using.

I'm not so lucky -- I'm writing a console UI library (Urwid) that anyone 
could use, and I'm trying to support as many encodings and terminals as 
possible.

I hope that the different terminal behaviors can be enumerated so that 
the console interface will degrade gracefully with less capable 
terminals.  The mined_2000 unicode text editor is a program that does 
this by detecting the terminal's behavior on startup. I'll probably take 
a similar approach.

Ian Ward


-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Jython inherit from Java class

2006-02-10 Thread Kent Johnson
Mark Fink wrote:
> I observed something strange when I tried to compile the jython class:
> 'assert' is a keyword, and may not be used as an identifier
> (try -source 1.3 or lower to use 'assert' as an identifier)
> public static void assert(PyObject test, PyObject message) {

> Looks like something in the Jython core causes the problem
> (org\python\core\Py.java) any Ideas what I can do?

I think jythonc is not compatible with Java 1.5, try compiling with 1.4.

Kent
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: is there a better way?

2006-02-10 Thread Lonnie Princehouse
everybody is making this way more complicated than it needs to be.

storage = list[:list.index(O)]

incidentally, "list" is the name of a type, so you might want to avoid
using it as a variable name.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Pulling all n-sized combinations from a list

2006-02-10 Thread [EMAIL PROTECTED]

Magnus Lycka wrote:
> [EMAIL PROTECTED] wrote:
> > But using the free SDK compiler from MS? That seems elusive.
>
> Have you seen this?
> http://www.vrplumber.com/programming/mstoolkit/

I have, although I haven't tried it as I was able to get a GMPY
Windows binary from someone else. It may be that probstat
is not as complicated as GMPY. So if I get some free time,
I might try it, would be worth it in the long run. Thanks for
pointing it out.

Nevertheless, my "elusive" comment was certainly justified:


Note also that the author of the document (Mike Fletcher)
has abandoned Windows as a development platform
(in some part because of the difficulties in getting a
working compiler to support the platform), and is thus
no longer actively maintaining this page.  While some
people are still reporting successes, others are having
difficulties with building certain projects.  The Toolkit
approach is, in short, a bit dicey as a platform for serious
development.


 I think it's safe to say most Windows users are NOT software
developers. If the professional software developers have trouble
figuring it out, what chance does an inexperienced end user have?

And for the record, I never implied that JD was obligated to provide
a Windows binary for his project. I was merely pointing out that
there are a lot of people not using his module because of the lack
of a Windows binary, so it really should come as no surprise that
people keep asking for solutions to combination/permutation
problems.

But it turns out he actually had one, which he graciously provided
in response to my observation. If I had kept my trap shut, I wouldn't
have it, would I? Squeaky wheels get grease. And, through my
blundering tests, he found a place where he should be raising an
exception, so he benefits also.

Luckily, not everyone has the "here's a nickel kid, get yourself a
better computer" attitude.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Jython inherit from Java class

2006-02-10 Thread Mark Fink
I observed something strange when I tried to compile the jython class:
D:\AUT_TEST\workspace\JyFIT\fit>jythonc JyFitServer.py
processing JyFitServer

Required packages:
  fitnesse.util
  java.io
  java.net
  fitnesse.components*

Creating adapters:

Creating .java files:
  JyFitServer module
JyFitServer extends fit.FitServer

Compiling .java to .class...
Compiling with args: ['C:\\Programme\\Java\\jdk1.5.0_06\\bin\\javac',
'-classpath',
'D:/AUT_TEST/JyFIT_port/fit;D:\\AUT_TEST\\Jython21\\jython.jar;C:\\Programme\\Java\\jdk1.5.0_06\\lib\\tools.jar;C:\\
Java\\jboss-4.0.0\\server\\default\\lib\\mysql-connector-java-2.0.14-bin.jar;C:\\Java\\jboss-4.0.0\\client\\jboss-j2ee.jar;C:\\Java\\jboss-4.0.0\\client\\jboss-client.jar;C:\\Java\\jboss-4.0.0\\client
\\jbosssx-client.jar;C:\\Java\\jboss-4.0.0\\client\\jnp-client.jar;C:\\Java\\jboss-4.0.0\\client\\jnet.jar;C:\\Java\\jboss-4.0.0\\client\\jboss-common-client.jar;C:\\Java\\jboss-4.0.0\\tomcat-4.1.x\\c
ommon\\lib\\servlet.jar;D:\\AUT_TEST\\Jython21\\jython.jar;D:\\AUT_TEST\\fitnesse\\fitnesse.jar;D:\\AUT_TEST\\JyFIT_port;%CLASSPATH%;.\\jpywork;;D:\\AUT_TEST\\Jython21\\Tools\\jythonc;D:\\AUT_TEST\\wo
rkspace\\JyFIT\\fit\\.;D:\\AUT_TEST\\Jython21\\Lib;D:\\AUT_TEST\\workspace\\JyFIT;D:\\AUT_TEST\\fitnesse\\fitnesse.jar;D:\\AUT_TEST\\Jython21',
'.\\jpywork\\JyFitServer.java']
1  D:\AUT_TEST\Jython21\org\python\core\Py.java:989: as of release 1.4,
'assert' is a keyword, and may not be used as an identifier
(try -source 1.3 or lower to use 'assert' as an identifier)
public static void assert(PyObject test, PyObject message) {
   ^
D:\AUT_TEST\Jython21\org\python\core\Py.java:995: as of release 1.4,
'assert' is a keyword, and may not be used as an identifier
(try -source 1.3 or lower to use 'assert' as an identifier)
public static void assert(PyObject test) {
   ^
D:\AUT_TEST\Jython21\org\python\core\Py.java:996: ')' expected
assert(test, Py.None);
   ^
D:\AUT_TEST\Jython21\org\python\parser\PythonGrammar.java:6739: as of
release 1.5, 'enum' is a keyword, and may not be used as an identifier
(try -source 1.4 or lower to use 'enum' as an identifier)
  for (java.util.Enumeration enum = jj_expentries.elements();
enum.hasMoreElements();) {
 ^
D:\AUT_TEST\Jython21\org\python\parser\PythonGrammar.java:6739: as of
release 1.5, 'enum' is a keyword, and may not be used as an identifier
(try -source 1.4 or lower to use 'enum' as an identifier)
  for (java.util.Enumeration enum = jj_expentries.elements();
enum.hasMoreElements();) {
  ^
D:\AUT_TEST\Jython21\org\python\parser\PythonGrammar.java:6740: as of
release 1.5, 'enum' is a keyword, and may not be used as an identifier
(try -source 1.4 or lower to use 'enum' as an identifier)
int[] oldentry = (int[])(enum.nextElement());
 ^
D:\AUT_TEST\Jython21\org\python\core\Py.java:996: incompatible types
found   : org.python.core.PyObject
required: boolean
assert(test, Py.None);
   ^
D:\AUT_TEST\Jython21\org\python\core\PyBeanProperty.java:36: warning:
non-varargs call of varargs method with inexact argument type for last
parameter;
cast to java.lang.Object for a varargs call
cast to java.lang.Object[] for a non-varargs call and to suppress this
warning
Object value = getMethod.invoke(iself, Py.EmptyObjects);
 ^
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: Some input files use unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
7 errors
1 warning

ERROR DURING JAVA COMPILATION... EXITING

D:\AUT_TEST\workspace\JyFIT\fit>
Looks like something in the Jython core causes the problem
(org\python\core\Py.java) any Ideas what I can do?

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: is there a better way?

2006-02-10 Thread Schüle Daniel
[...]

> I have been using something like this:
> _
> 
> while list[0] != O:
> storage.append(list[0])
> list.pop(0)
> if len(list) == 0:
> break
> _
> 
> But this seems ugly to me, and using "while" give me the heebies.  Is
> there a better approach?

 >>> lst = [1,2,3,4,5,0,0,0,0]
 >>> del lst[lst.index(0):]
 >>> lst
[1, 2, 3, 4, 5]
 >>>

Regards, Daniel

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: is there a better way?

2006-02-10 Thread Schüle Daniel
[...]

> 
> What not
> 
> for x in list:
>   if x == O:
> break
>   storage.append(x)
> 

i think this may take too long
better aproach would be to test for zero from the end

Regards, Daniel

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: ordered sets operations on lists..

2006-02-10 Thread Raymond Hettinger
[Amit Khemka]
> > Hello, Is there a *direct* way of doing set operations on lists which
> > preserve the order of the input lists ?
> > For Ex.  l1 = [1, 5, 3, 2, 4, 7]
> > l2 =  [3, 5,  10]
> >
> > and (l1 intersect l2)  returns [5, 3]  (and (l2 intersect l1)

[bonono]
> what do you mean by "direct" way ? ugly(some said) one liner ?
>
> filter(set(l1).intersection(set(l2)).__contains__, l1)
> filter(set(l1).intersection(set(l2)).__contains__, l2)

The intersection step is unnecessary, so the answer can be simplified a
bit:

>>> filter(set(l2).__contains__, l1)
[5, 3]
>>> filter(set(l1).__contains__, l2)
[3, 5]

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: is there a better way?

2006-02-10 Thread Scott David Daniels
[EMAIL PROTECTED] wrote:
> Problem:
> 
> You have a list of unknown length, such as this: list =
> [X,X,X,O,O,O,O].  You want to extract all and only the X's.  You know
> the X's are all up front and you know that the item after the last X is
> an O, or that the list ends with an X.  There are never O's between
> X's.
> 
> I have been using something like this:
> while list[0] != O:
> storage.append(list[0])
> list.pop(0)
> if len(list) == 0:
> break
> But this seems ugly to me, and using "while" give me the heebies.  Is
> there a better approach?
> 

Your names could be better as someone mentioned.
 ex, oh = 7, 13   # for example
 data = [ex, ex, ex, oh, oh, oh, oh]
If you need a list distinct from the original:
 try:
 result = data[: data.index(oh)]
 except ValueError:
 result = list(data)

Or you could simply:
 try:
 data = data[: data.index(oh)]
 except ValueError:
 pass
and data will be either the sublist you want or the original list.

-- 
-Scott David Daniels
[EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Legality of using Fonts

2006-02-10 Thread Scott David Daniels
Kamilche wrote:
> I have a question for all you Pythoneers out there. I'm making a game
> with Python, and have a need for fonts. I am currently using a free
> TrueType font, but am considering switching to a bitmap font instead.
> 
> Let's say I own a font, and use it in a paint program to 

Typically you don't "own" a font, but you have a license to use it.
You need to read the license to figure out what you are allowed to do
with it.

--Scott David Daniels
[EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: ordered sets operations on lists..

2006-02-10 Thread Scott David Daniels
Amit Khemka wrote:
> Hello, Is there a *direct* way of doing set operations on lists which
> preserve the order of the input lists ?
Nope

> For Ex.  l1 = [1, 5, 3, 2, 4, 7]
> l2 =  [3, 5,  10]
> 
> and (l1 intersect l2)  returns [5, 3]  (and (l2 intersect l1) 
> returns [3, 5])

However:
 intersection = set(list1) & set(list2)
 [element for element in list1 if element in intersection]
or
 [element for element in list2 if element in intersection]
Give you the result you'd like.

--Scott David Daniels
[EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Newbie Q: dynamically assigning object attribute

2006-02-10 Thread Ben Wilson
Well, my Perl way of doing it would be to have all attributes in a dict
(hash), then create the accessor vi a dynamic function. I knew Python
would have a right way to do it for Python, but when I went looking I
neglected to look at the core of the language. I suppose I'm just too
accustomed to the TIMTOWTDY approach to expect the
one-ring-to-bind-them-all solution. :-) It's a mental shift on my part,
to be certain.

What I was actually doing was reading a user configuration file and
setting an object's variables--the example I got was a fairly close
approximation of how I was trying to approach it before setattr().

Thanks,
Ben

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: by reference

2006-02-10 Thread dirvine
Thanks but I am a bit unsure as to what error I have made by posting
this question. I am not trying to be funny but can you give me a
pointer to the issue.

Many thanks
David

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Tkinter, X-windows and ebay

2006-02-10 Thread Cameron Laird
In article <[EMAIL PROTECTED]>,
Bob Greschke <[EMAIL PROTECTED]> wrote:
>
>"Paul Rubin"  wrote in message 
>news:[EMAIL PROTECTED]
>> "Bob Greschke" <[EMAIL PROTECTED]> writes:
>>> What I came up with was the user can just create a text file (a kind
>>> of a transaction log of what things were done to the copy of the
>>> database on his machine), then cut and paste that text into a window
>>> created on their machine by the main database program (using
>>> X-windows, ssh, etc.), then the main program can read the contents
>>> of that text field and update the main copy of the database.
>>>
>>> It should work. :)
>>
>> Yuck!  Why not use an http interface instead of the remote tkinter
>> interface?  Then the user would interact with your app through a web
>> browser, giving a familiar UI as well as giving that upload button
>> (which tells the browser to upload the file).
>
>Mainly because the user may be in the middle of the Himalayas trying to 
>create paperwork for equipment being shipped to Japan and Chile.  The 
>Internet is not always an option in our line of work.  We need to have 
>standalone everythings.  We don't live in your real world. :)
>
>The two databases (the one on the user's laptop, and the one back at the 
>office) don't need to be reconciled until the user gets back.  We just need 
>to (eventually) know which pieces of equipment were sent to Japan, and which 
>went to Chile.
.
.
.
Certainly.  And, if you're content with what you have, that's
great; *I* certainly do enough funny things with Tkinter and 
X.  But what you *can* do is deploy the end-user desktop with
a browser pointed to a local Web page, presumably one with 
enough client-side processing to prepare a form.  Then, when
he's within range of an IP address, he selects an "upload"
link, and you get all the HTTP-related advantages Paul and
others have mentioned.
-- 
http://mail.python.org/mailman/listinfo/python-list


Martin Franklin's Tkinter/Tile wrapper--where'd it go?

2006-02-10 Thread Kevin Walzer
I believe Martin Franklin wrote a Tile.py wrapper for the Tk/Tile
extension, which adds theming to the core Tk widget set. It used to
reside here:

http://mfranklin.is-a-geek.org/docs/Tile/index.html

That server seems to be down. Anyone know if the wrapper is available
elsewhere? Or if someone else has written a Tile wrapper?

-- 
Kevin Walzer
iReveal: File Search Tool
http://www.wordtech-software.com
-- 
http://mail.python.org/mailman/listinfo/python-list



Re: html entity to unicode

2006-02-10 Thread Peter Maas
[EMAIL PROTECTED] schrieb:
> Hi,
> 
> I'm parsing html. I have a page with a lot of html enitties for hebrew
> characters. When i print what i get are blanks, dots and commas. How
> can i decode this entities to unicode charachters?

Python doc

13.4 htmlentitydefs -- Definitions of HTML general entities

[...]

name2codepoint
A dictionary that maps HTML entity names to the Unicode codepoints. New in 
version 2.3.

codepoint2name
A dictionary that maps Unicode codepoints to HTML entity names. New in version 
2.3.

Peter Maas Aachen
-- 
http://mail.python.org/mailman/listinfo/python-list


ANN: Python interface to Microsoft Outlook Web Access

2006-02-10 Thread Adrian Holovaty
Hi all,

Because I telecommute, I'm limited to using my company's webmail
interface, Microsoft Outlook Web Access, rather than having direct POP
or IMAP access to e-mail. This isn't ideal, for several reasons:

* Outlook Web Access has a horrendous user interface in any browser
other than Internet Explorer. (And I'm on Linux, so I can't use
Internet Explorer.) It's hard to search, the icons are unintuitive, it
encourages top-posting and doesn't have the basic benefits of a desktop
e-mail app, such as spell-checking and address auto-completion.
* Using webmail forces me to keep a browser window/tab open to
check messages. And Outlook Web Access doesn't auto-refresh, so I have
to remember to click "Inbox" every so often to get the latest messages.
This is a huge disruption.
* It's just simpler and more efficient to have all my e-mail in one
place.

So I figured I'd do a bit of programming to make my life easier. The
result: weboutlook, a Python library that screen-scrapes Outlook Web
Access. It can:

* Log into a Microsoft Outlook Web Access account on a given server
with a given username and password.
* Retrieve all e-mail IDs from the first page of your Inbox.
* Retrieve all e-mail IDs from the first page of any folder in your
webmail (such as "Sent Items").
* Retrieve the full, raw source of the e-mail with a given ID.
* Delete an e-mail with a given ID (technically, move it to the
"Deleted Items" folder).

Also, I've included a Python implementation of a POP server that
provides a POP interface to the scraper. This means I can point my
desktop e-mail client at the script, my e-mail client will think it's a
normal POP server, and my e-mails will download nicely into my desktop
app, with the screen-scraper running silently behind the scenes.

I put this together in my free time, and it's been working nicely for a
week, so I'm open-sourcing it for other poor souls who've been
sentenced to use Outlook Web Access. I presented this at yesterday's
Chicago Python Users Group meeting and was surprised to see that, even
in a group of only 30 people, 5 or 6 people used Outlook Web Access
through their company. I hope somebody finds this useful.

http://www.holovaty.com/code/weboutlook/

Please send comments and improvements to [EMAIL PROTECTED]

Adrian

--
Adrian Holovaty
holovaty.com | djangoproject.com | chicagocrime.org

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: random playing soundfiles according to rating.

2006-02-10 Thread Ben Cartwright
kpp9c wrote:
> I've been looking at some of the suggested approaches and looked a
> little at Michael's bit which works well bisect is a module i
> always struggle with (hee hee)
>
> I am intrigued by Ben's solution and Ben's distilled my problem quite
> nicely

Thanks!-)  Actually, you should use Michael's solution, not mine.  It
uses the same concept, but it finds the correct subinterval in O(log n)
steps (by using bisect on a cached list of cumulative sums).  My code
takes O(n) steps -- this is a big difference when you're dealing with
thousands of items.

> but, welli don't understand what "point" is doing with
> wieght for key, weight for zlist

This line:
point = random.uniform(0, sum(weight for key, weight in zlist))
Is shorthand for:
total = 0
for key, weight in zlist:
total += weight
point = random.uniform(0, total)

> furthermore, it barfs in my
> interpreter... (Python 2.3)

Oops, that's because it uses generator expressions
(http://www.python.org/peps/pep-0289.html), a 2.4 feature.  Try
rewriting it longhand (see above).  The second line of the test code
will have to be changed too, i.e.:
  >>> counts = dict([(key, 0) for key, weight in data])

--Ben

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: get output of cmd-line command under MS windows

2006-02-10 Thread calmar
On 2006-02-08, Bernard Lebel <[EMAIL PROTECTED]> wrote:

Hi Bernhard and all,

> oPipe = os.popen( "run C:/program files/my app/executable.exe" )
>
> while 1:
>   sLine = oPipe.read()
>   print sLine
>   if sLine == '':
>   print 'No more line from pipe, exit.'
>   break
>

I see. I saw also os.popen("").read() or so.

Anyway, not sure if that would also catch stderr?

But doesn't matter. It seems, imagemagick (binaries) won't provide
proper error-codes, but at least when it prints something, something was
not ok probably. 

I will check the resulting file, to see if everything went ok, and try
to catch the output like you mentioned.

thanks a lot
marco

-- 
  calmar

  (o_  It rocks: LINUX + Command-Line-Interface
  //\
  V_/_ http://www.calmar.ws
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: is there a better way?

2006-02-10 Thread Paul McGuire
"Paul McGuire" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> <[EMAIL PROTECTED]> wrote in message
> news:[EMAIL PROTECTED]
> > Problem:
> >
> > You have a list of unknown length, such as this: list =
> > [X,X,X,O,O,O,O].  You want to extract all and only the X's.  You know
> > the X's are all up front and you know that the item after the last X is
> > an O, or that the list ends with an X.  There are never O's between
> > X's.
> >
> > I have been using something like this:
> > _
> >
> > while list[0] != O:
> > storage.append(list[0])
> > list.pop(0)
> > if len(list) == 0:
> > break
> > _
> >
> > But this seems ugly to me, and using "while" give me the heebies.  Is
> > there a better approach?
> >
> > hope this is clear.
> > thanks
> >
> Use itertools.
>
> >>> import itertools
> >>> lst = "X,X,X,O,O,O,O,O,X,X,X,X,O,X".split(",")
> >>> [z for z in itertools.takewhile(lambda x:x=="X",lst)]
> ['X', 'X', 'X']
>
>
> -- Paul
>

duh, last line should be:

>>> list(itertools.takewhile(lambda x:x=="X",lst))
['X', 'X', 'X']

(Also, don't name variables "list")

-- Paul


-- 
http://mail.python.org/mailman/listinfo/python-list


Re: is there a better way?

2006-02-10 Thread Paul McGuire
<[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> Problem:
>
> You have a list of unknown length, such as this: list =
> [X,X,X,O,O,O,O].  You want to extract all and only the X's.  You know
> the X's are all up front and you know that the item after the last X is
> an O, or that the list ends with an X.  There are never O's between
> X's.
>
> I have been using something like this:
> _
>
> while list[0] != O:
> storage.append(list[0])
> list.pop(0)
> if len(list) == 0:
> break
> _
>
> But this seems ugly to me, and using "while" give me the heebies.  Is
> there a better approach?
>
> hope this is clear.
> thanks
>
Use itertools.

>>> import itertools
>>> lst = "X,X,X,O,O,O,O,O,X,X,X,X,O,X".split(",")
>>> [z for z in itertools.takewhile(lambda x:x=="X",lst)]
['X', 'X', 'X']


-- Paul


-- 
http://mail.python.org/mailman/listinfo/python-list


Re: is there a better way?

2006-02-10 Thread Tim Chase
> You have a list of unknown length, such as this: list =
> [X,X,X,O,O,O,O].  You want to extract all and only the X's.  You know
> the X's are all up front and you know that the item after the last X is
> an O, or that the list ends with an X.  There are never O's between
> X's.
> 
> I have been using something like this:
> _
> 
> while list[0] != O:
> storage.append(list[0])
> list.pop(0)
> if len(list) == 0:
> break
> _

While it doesn't modify your list, you can try something like

storage = [q for q in myList if q != O]

If you've already got stuff in storage that you want to keep, you 
can use

storage.extend([q for q in myList if q != O])

I suppose, if you wanted to remove all the O's, you could then 
just do

myList = [q for q in myList if q == O]

(trickiness using Oh's vs. using zeros...)

-tkc






-- 
http://mail.python.org/mailman/listinfo/python-list


Re: is there a better way?

2006-02-10 Thread snoe

[EMAIL PROTECTED] wrote:
> Problem:
>
> You have a list of unknown length, such as this: list =
> [X,X,X,O,O,O,O].  You want to extract all and only the X's.  You know
> the X's are all up front and you know that the item after the last X is
> an O, or that the list ends with an X.  There are never O's between
> X's.
>
> I have been using something like this:
> _
>
> while list[0] != O:
> storage.append(list[0])
> list.pop(0)
> if len(list) == 0:
> break
> _
>
> But this seems ugly to me, and using "while" give me the heebies.  Is
> there a better approach?
>
> hope this is clear.
> thanks


There's a few ways to do this, really depends on :

mylist = [1,2,3,4,5,6,0,0,0]

list comprehension (will get ALL non zeros, and strip out all zeros,
but is different from your function):
[x for x in mylist if x != 0]

list slice(same as your function):
mylist[:mylist.index(0)]

Depends what you want to happen if your list is something like:
[1,2,3,0,4,5,6,0,0]
[0,1,2,3,4,5,6]
[0,1,2,3,4,5,6,0]
[1,2,3,4,5,6]

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Are there memory limits for external C modules?

2006-02-10 Thread [EMAIL PROTECTED]
[EMAIL PROTECTED] wrote:
> I was able to modify my C code so that instead of being a Python
> module, it runs as a standalone binary, and it works as it should.
> Calling it with os.spawn* works.  The two versions are essentially the
> same, the primary differences being the necessary difference in how
> arguments and return values are handled.
>
> This will work if necessary, but I would think having it as a Python
> module would be slightly more elegant and efficient since we avoid the
> overhead of setting up new processes.

I was able to resolve this issue. I was missing a call into Ethereal
that allocated necessary memory.  Now the Python module version works,
and some various GLib assert warnings I was getting have gone away as
well.

Some testing has shown that the Python module version is quicker; I'm
assuming that the overhead involved in setting up a separate process
was slowing things down.  There was a noticeable difference.

- David

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Newbie Q: dynamically assigning object attribute

2006-02-10 Thread Sion Arrowsmith
Ben Wilson <[EMAIL PROTECTED]> wrote:
>I would like to dynamically assign object attributes:
>
>dict = {
> a : 1,
> b : 2,
>}
>
>for key,val in dict :
>  obj.key = val
>
>I've googled to no effect, or maybe I'm needing to be hit with the
>appropriately sized clue-by-four.

The conventional clue-by-four applied to this question is "Don't
do that: just put the dictionary (or a copy of it) in the object
with obj.d = d (and don't shadow the built-in dict while you're
at it)." Having spent significant portions of the last two days
coping with the mess of adding functionality to a class written
by someone who thought doing what you want to do was a Good Idea,
I can only concur with that conventional wisdom.

Really. Don't do it. (Unless you have a damn good reason. In
which case, you've already been pointed at setattr().)

-- 
\S -- [EMAIL PROTECTED] -- http://www.chaos.org.uk/~sion/
  ___  |  "Frankly I have no feelings towards penguins one way or the other"
  \X/  |-- Arthur C. Clarke
   her nu becomeþ se bera eadward ofdun hlæddre heafdes bæce bump bump bump
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: is there a better way?

2006-02-10 Thread Jeremy Sanders
[EMAIL PROTECTED] wrote:

> You have a list of unknown length, such as this: list =
> [X,X,X,O,O,O,O].  You want to extract all and only the X's.  You know
> the X's are all up front and you know that the item after the last X is
> an O, or that the list ends with an X.  There are never O's between
> X's.

What not

for x in list:
  if x == O:
break
  storage.append(x)

??

-- 
Jeremy Sanders
http://www.jeremysanders.net/
-- 
http://mail.python.org/mailman/listinfo/python-list


is there a better way?

2006-02-10 Thread [EMAIL PROTECTED]
Problem:

You have a list of unknown length, such as this: list =
[X,X,X,O,O,O,O].  You want to extract all and only the X's.  You know
the X's are all up front and you know that the item after the last X is
an O, or that the list ends with an X.  There are never O's between
X's.

I have been using something like this:
_

while list[0] != O:
storage.append(list[0])
list.pop(0)
if len(list) == 0:
break
_

But this seems ugly to me, and using "while" give me the heebies.  Is
there a better approach?

hope this is clear.
thanks

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Jython inherit from Java class

2006-02-10 Thread Mark Fink
Alan, Kent, many thanks this really helped!
But there is still a problem I guess with inheritance. I use the java
testsuit supplied with the original to test the server. If I use the
Java FitServer the testsuite can be completed. I commented everything
out from my class and it does not work??
Thats the trace when I run the JUnit testsuit:
java.io.IOException: CreateProcess: jython
D:\AUT_TEST\workspace\JyFIT\fit\JyFitServer.py
-Dpython.path='D:\AUT_TEST\workspace\JyFIT'
D:\AUT_TEST\fitnesse\fitnesse.jar localhost 1234 23 error=2
at java.lang.ProcessImpl.create(Native Method)
at java.lang.ProcessImpl.(Unknown Source)
at java.lang.ProcessImpl.start(Unknown Source)
at java.lang.ProcessBuilder.start(Unknown Source)
at java.lang.Runtime.exec(Unknown Source)
at java.lang.Runtime.exec(Unknown Source)
at java.lang.Runtime.exec(Unknown Source)
at
FitServerTest.FitServerTest.prepareSessionProcess(FitServerTest.java:163)
at
FitServerTest.FitServerTest.testSimpleStartUp(FitServerTest.java:36)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at junit.framework.TestCase.runTest(TestCase.java:154)
at junit.framework.TestCase.runBare(TestCase.java:127)
at junit.framework.TestResult$1.protect(TestResult.java:106)
at junit.framework.TestResult.runProtected(TestResult.java:124)
at junit.framework.TestResult.run(TestResult.java:109)
at junit.framework.TestCase.run(TestCase.java:118)
at junit.framework.TestSuite.runTest(TestSuite.java:208)
at junit.framework.TestSuite.run(TestSuite.java:203)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:478)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:344)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)

Unfortunately I do not get much information at the prompt because both
Java FitServer and JyFitServer behave the same there.
D:\AUT_TEST>jython D:\\AUT_TEST\\workspace\\JyFIT\\fit\\JyFitServer.py
-Dpython.path='D:\\AUT_TEST\\workspace\\JyFIT'
D:\\AUT_TEST\\fitnesse\\fitnesse.jar localhost 1234 23
Traceback (innermost last):
  File "D:\\AUT_TEST\\workspace\\JyFIT\\fit\\JyFitServer.py", line 42,
in ?
java.net.ConnectException: Connection refused: connect
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:333)
at
java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:195)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:182)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366)
at java.net.Socket.connect(Socket.java:507)
at java.net.Socket.connect(Socket.java:457)
at java.net.Socket.(Socket.java:365)
at java.net.Socket.(Socket.java:178)
at fit.FitServer.establishConnection(Unknown Source)
at fit.FitServer.establishConnection(Unknown Source)
at fit.FitServer.run(Unknown Source)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at
org.python.core.PyReflectedFunction.__call__(PyReflectedFunction.java)
at org.python.core.PyMethod.__call__(PyMethod.java)
at org.python.core.PyObject.__call__(PyObject.java)
at org.python.core.PyInstance.invoke(PyInstance.java)
at
org.python.pycode._pyx0.f$0(D:\\AUT_TEST\\workspace\\JyFIT\\fit\\JyFitServer.py:42)
at
org.python.pycode._pyx0.call_function(D:\\AUT_TEST\\workspace\\JyFIT\\fit\\JyFitServer.py)
at org.python.core.PyTableCode.call(PyTableCode.java)
at org.python.core.PyCode.call(PyCode.java)
at org.python.core.Py.runCode(Py.java)
at org.python.core.__builtin__.execfile_flags(__builtin__.java)
at
org.python.util.PythonInterpreter.execfile(PythonInterpreter.java)
at org.python.util.jython.main(jython.java)

java.net.ConnectException: java.net.ConnectException: Connection
refused: connect

## And the Java FitServer:
D:\AUT_TEST>java -cp D:\\AUT_TEST\\fitnesse\\fitnesse.jar fit.FitServer
localhost 1234 23
Exception in thread "main" java.net.ConnectException: Connection
refused: connect
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(Unknown Source)
at java.net.PlainSocketImpl.connectToAddress(Unknown Source)
at java.net.PlainSocketImpl.connect(

Re: Tkinter, X-windows and ebay

2006-02-10 Thread Bob Greschke

"Paul Rubin"  wrote in message 
news:[EMAIL PROTECTED]
> "Bob Greschke" <[EMAIL PROTECTED]> writes:
>> What I came up with was the user can just create a text file (a kind
>> of a transaction log of what things were done to the copy of the
>> database on his machine), then cut and paste that text into a window
>> created on their machine by the main database program (using
>> X-windows, ssh, etc.), then the main program can read the contents
>> of that text field and update the main copy of the database.
>>
>> It should work. :)
>
> Yuck!  Why not use an http interface instead of the remote tkinter
> interface?  Then the user would interact with your app through a web
> browser, giving a familiar UI as well as giving that upload button
> (which tells the browser to upload the file).

Mainly because the user may be in the middle of the Himalayas trying to 
create paperwork for equipment being shipped to Japan and Chile.  The 
Internet is not always an option in our line of work.  We need to have 
standalone everythings.  We don't live in your real world. :)

The two databases (the one on the user's laptop, and the one back at the 
office) don't need to be reconciled until the user gets back.  We just need 
to (eventually) know which pieces of equipment were sent to Japan, and which 
went to Chile.

Bob


-- 
http://mail.python.org/mailman/listinfo/python-list


Re: AdaptionFailure: How to use Interfaces with PyProtocols ?

2006-02-10 Thread Nebur
Yes, I adapted the instance, and it's working.That's it.
Thank you !
 Nebur

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: ordered sets operations on lists..

2006-02-10 Thread bonono

Amit Khemka wrote:
> Hello, Is there a *direct* way of doing set operations on lists which
> preserve the order of the input lists ?
> For Ex.  l1 = [1, 5, 3, 2, 4, 7]
> l2 =  [3, 5,  10]
>
> and (l1 intersect l2)  returns [5, 3]  (and (l2 intersect l1)
> returns [3, 5])
>
what do you mean by "direct" way ? ugly(some said) one liner ?

filter(set(l1).intersection(set(l2)).__contains__, l1)
filter(set(l1).intersection(set(l2)).__contains__, l2)

-- 
http://mail.python.org/mailman/listinfo/python-list


  1   2   >