Re: Get Special Folders (ie Desktop location)

2004-12-01 Thread Colin Steadman
> 
> You can do that in Python using the pywin32 extensions
> either by using the Wshell objects as you have done:
> 
> 
> 
> import win32com.client
> WShell = win32com.client.Dispatch ("WScript.Shell")
> WShell.SpecialFolders ("Desktop")
> 
> 
> 
> or by using the shell module from the same package.
> I've got a module which wraps the common ones for
> convenience:
> 
> http://tgolden.sc.sabren.com/python/winshell.html
> 
> but essentially what you're doing is this:
> 
> 
> from win32com.shell import shell, shellcon
> 
> shell.SHGetPathFromIDList (
>   shell.SHGetSpecialFolderLocation (
> 0, shellcon.CSIDL_DESKTOP
>   )
> )
> 
> 
> TJG


Thank you both!

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


IMAP UTF-7, any codec for that anywhere?

2004-12-01 Thread Max M
Is there any codec available for handling The special UTF-7 codec for IMAP?
I have searched the web for info, but there only seem to be discussions 
about it. Not actual implementations.

This is what I am talking about:
http://www.faqs.org/rfcs/rfc2060.html
5.1.3.  Mailbox International Naming Convention
--
hilsen/regards Max M, Denmark
http://www.mxm.dk/
IT's Mad Science
--
http://mail.python.org/mailman/listinfo/python-list


Re: pre-PEP generic objects

2004-12-01 Thread Peter Otten
Steven Bethard wrote:

> Peter Otten wrote:
>> Steven Bethard wrote:
>> 
>>>def __eq__(self, other):
>>>"""x.__eq__(y) <==> x == y"""
>>>return (isinstance(other, self.__class__)
>>>and self.__dict__ == other.__dict__)
>> 
>> This results in an asymmetry:
>> 
> [snip]
>> 
>> Whether this is intended, I don't know. If someone can enlighten me...

> Unintended.  

Oops, I meant CPython's rich comparison, not your __eq__() implementation.

> I'll switch to 
>  self.__class__ == other.__class__
> or
>  type(self) == type(other)
> Any preference?

Normally none of them. The former if hard pressed because all old-style
classes have the same type(). But it doesn't really matter here.

Peter

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


Re: Python 2.4 Uninstall Entry in WinXP Registry

2004-12-01 Thread "Martin v. Löwis"
Brad Tilley wrote:
Python 2.3 placed a registry key under:
'HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Python2.3' 
[...]
Python 2.4 does not use this registry entry on the two machines I have 
installed it on... any tips on how to locate this?
It's under
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{82D9302E-F209-4805-B548-52087047483A}
which is the product code of Python 2.4. Notice that Python 2.4.1
will use a different product code.
However, if you merely want to avoid that users remove the package,
you can set the ARPNOREMOVE property during installation, e.g.
msiexec /i python24.msi ARPNOREMOVE=1
You might want to set ARPNOMODIFY and ARPNOREPAIR as well.
If you cannot readily pass that property on the command line during
installation, you can use orca.exe (or a python script) to add this
property to the Property table of python24.msi.
If you have W2k or later, you can also set the "NoRemove" registry
value under the key above, to hide the remove feature after
installation.
HTH,
Martin
--
http://mail.python.org/mailman/listinfo/python-list


Re: IMAP UTF-7, any codec for that anywhere?

2004-12-01 Thread Brian Quinlan
Max M wrote:
Is there any codec available for handling The special UTF-7 codec for IMAP?
I have searched the web for info, but there only seem to be discussions 
about it. Not actual implementations.
Is there something special do you need or is recipe OK?
>>> u"\u00ff".encode('utf-7')
'+AP8-'
Cheers,
Brian
--
http://mail.python.org/mailman/listinfo/python-list


2.4 or 2.3.4 for 2.3 software?

2004-12-01 Thread Jens Bloch Helmers
Can we expect the current release of 2.4 to be just as reliable as
2.3.4 for 2.3 compliant software?

Thanks for any help!
Jens
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: RELEASED Python 2.4 (final)

2004-12-01 Thread BJörn Lindqvist
Christmas came early this year. Thank you all nice Python developers. 

-- 
mvh Björn
--
http://mail.python.org/mailman/listinfo/python-list


Re: IMAP UTF-7, any codec for that anywhere?

2004-12-01 Thread Max M
Brian Quinlan wrote:
> Max M wrote:
>
>> Is there any codec available for handling The special UTF-7 codec for
>> IMAP?
> Is there something special do you need or is recipe OK?
>
>  >>> u"\u00ff".encode('utf-7')
> '+AP8-'
A recipe would be excellent. Unfortunately yours is no right. It should 
have looke like:

>>> imapUTF7Encode(u"\u00ff")
'&AP8-'
I believe you missed the 'special' in "The special UTF-7 codec for IMAP?"
Imap folders use a non-standard version of utf-7, where some characters 
are different.

I found som messages from 2001 on the net between a few Python unicode 
developers, where they discuss implementing it. But I cannot find an 
implementation anywhere.

I found a perl module that converts to/from the codec, but as usual that 
is regex hell. Well ok its not that difficult, but I still need to think 
to hard to parse Perl regex'

--
hilsen/regards Max M, Denmark
http://www.mxm.dk/
IT's Mad Science
--
http://mail.python.org/mailman/listinfo/python-list


Re: 2.4 or 2.3.4 for 2.3 software?

2004-12-01 Thread Gerhard Haering
On Wed, Dec 01, 2004 at 10:23:55AM +0100, Jens Bloch Helmers wrote:
> Can we expect the current release of 2.4 to be just as reliable as
> 2.3.4 for 2.3 compliant software?

Only time will tell.

I myself had never had any problems with 2.x.0 versions of Python. Only early
2.0.x had a few problems in the C API for me.

-- Gerhard


signature.asc
Description: Digital signature
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Question on sorting

2004-12-01 Thread Lad
wes weston <[EMAIL PROTECTED]> wrote in message news:<[EMAIL PROTECTED]>...
> Lad wrote:
> > Hi,
> > I have a file of records of 4 fields each.
> > Each field is separated by a semicolon. That is
> > 
> > Filed1;Ffield2;Field3;Field4
> > 
> > But there may be also empty records such as
> > 
> > (only semicolons).
> > 
> > For sorting I used
> > #
> > lines = file('Config.txt').readlines()# a file I want to sort
> > lines.sort()
> > ff=open('ConfigSorted.txt','w')# sorted file
> > ff.writelines(lines)
> > ff.close()
> > ###
> > It was sorted but empty records were first. I need them to be last(at
> > the end of the file). How can I do that?
> > 
> > Thanks for help
> > Lad
> 
> Lad,
> The sort call can have a function name as an arg. You
> could do:
> 
> def mycompare(s1,s2):
> #return -1 to put s1's at front; 1 to put s1's at back; 0 for a tie
> #if s1=="" and s2<>"": return 1
> 
> lines.sort(mycompare)
> 
Wes,
Thank you for reply. But I do not understand mycompare function. Can
you please explain to me how it should work? Thanks

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


Re: decorators ?

2004-12-01 Thread BJörn Lindqvist
Some more decorator examples.

How to create abstract methods using an @absractmethod decorator:
http://www.brpreiss.com/books/opus7/html/page117.html

Generics, property getters and setters. I don't know what these
decorators are supposed to do:
http://www.cis.upenn.edu/~edloper/pydecorators.html -

And according to this,
http://www.prothon.org/pipermail/prothon-user/2004-August/003173.html,
one use of decorators is to put a functions docstring before the def
f(): line like this:

@doc("""blabla does something.""")
def blabla():

Here is one decorator for optimizing:
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/277940

I think the essence of decorators is that it makes it possible to do
in Python what you in other languages do with method qualifiers. This
declaration in Java

public synchronized static void doStuff()

would you write in Python as

@public
@synchronized
@staticmethod
def doStuff():

I haven't seen an example of a @synchronized decorator, but I assume
it is possible. Hopefully, it is possible to create a @private
decorator which throws some kind of exception when a private method is
accessed from outside the class. If that is possible, then it would
also be nice to have a @public decorator which doesn't do anything. As
far as I know, only two decorators are included in the standard
library in Python 2.4, @staticmethod and @classmethod. That is a
little unfortunate, because many more "obvious ones" could have been
included. The devs are probably planning to correct that in the coming
versions.
That is all I know about decorators. Or rather THINK I know from
reading stuff on the internet. Please don't flame me if I'm wrong. :)

-- 
mvh Björn
--
http://mail.python.org/mailman/listinfo/python-list


Re: Question on sorting

2004-12-01 Thread Peter Otten
Lad wrote:

> wes weston <[EMAIL PROTECTED]> wrote in message
> news:<[EMAIL PROTECTED]>...
>> Lad wrote:
>> > Hi,
>> > I have a file of records of 4 fields each.
>> > Each field is separated by a semicolon. That is
>> > 
>> > Filed1;Ffield2;Field3;Field4
>> > 
>> > But there may be also empty records such as
>> > 
>> > (only semicolons).
>> > 
>> > For sorting I used
>> > #
>> > lines = file('Config.txt').readlines()# a file I want to sort
>> > lines.sort()
>> > ff=open('ConfigSorted.txt','w')# sorted file
>> > ff.writelines(lines)
>> > ff.close()
>> > ###
>> > It was sorted but empty records were first. I need them to be last(at
>> > the end of the file). How can I do that?
>> > 
>> > Thanks for help
>> > Lad
>> 
>> Lad,
>> The sort call can have a function name as an arg. You
>> could do:
>> 
>> def mycompare(s1,s2):
>> #return -1 to put s1's at front; 1 to put s1's at back; 0 for a tie
>> #if s1=="" and s2<>"": return 1
>> 
>> lines.sort(mycompare)
>> 
> Wes,
> Thank you for reply. But I do not understand mycompare function. Can
> you please explain to me how it should work? Thanks

compare(a, b) is just a function for comparing two items/lines. I must
return -1 if ab, and 0 if a==b. For example the following
compare moves the "" records to the end and keeps the order of others
unaffected:

>>> items = ["", ";a;b;;", ";b;a;;", "a;b;c;d;e", "a;;;d;e"]
>>> def compare(a, b):
... return cmp(a == "", b == "") or cmp(a, b)
...
>>> items.sort(compare)
>>> items
[';a;b;;', ';b;a;;', 'a;;;d;e', 'a;b;c;d;e', '']

As Eddie Corns pointed out, you left some doubt whether that is really what
you want. Here is a more complex compare() that handles the lines as
columns split by ";" and puts empty columns last in the sorting order:

>>> def key(row):
... return [(not col, col) for col in row.split(";")]
...
>>> def compare(a, b):
... return cmp(key(a), key(b))
...
>>> items.sort(compare)
>>> items
['a;b;c;d;e', 'a;;;d;e', ';a;b;;', ';b;a;;', '']

If you are on Python 2.4, you don't need the compare() detour and can use
key() directly:

>>> items.sort(key=key)
>>> items
['a;b;c;d;e', 'a;;;d;e', ';a;b;;', ';b;a;;', '']

Finally, the "" lines don't seem to carry any information - why not
filter them out completely?

>>> items = [line[:-1] for line in file("cfg.txt", "U") if line != "\n"]


Peter

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


Regular Expression Problem...

2004-12-01 Thread andrea . gavana
Hello NG,

 I am quite new with Python... I'm writing an application that does
also some regexp things on strings, but I'm having problem about
identifying/extracting a substring from another string. What I have to do
is to extract all the strings that begins with a "$" character, but
excluding characters like "." (point) and "'" (single quote) and "\" "/"
(slashes). For example I have:

1) This Is An $EXAMPLE String
2) This Is An $EXAMPLE.String
3) 'This Is An $EXAMPLE'
4) This Is An \$EXAMPLE\String;

I would like to extract only the "keyword" $EXAMPLE and what I'm using at
the moment is:

#CODE BEGIN
import re

mystring = "This Is An \$EXAMPLE\String;"
regex = re.compile("[\$]+\S*",re.IGNORECASE)
keys = regex.findall(mystring)

#CODE END

Obviously this code returns things like $EXAMPLE', $EXAMPLE/, $EXAMPLE. and
so on...
Does anyone have a suggestion?

Thank you a lot.

Andrea.

--

Message for the recipient only, if received in error, please notify the
sender and read http://www.eni.it/disclaimer/

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


Re: Regular Expression Problem...

2004-12-01 Thread Jorge Godoy
[EMAIL PROTECTED] writes:

> #CODE BEGIN
> import re
>
> mystring = "This Is An \$EXAMPLE\String;"
> regex = re.compile("[\$]+\S*",re.IGNORECASE)
> keys = regex.findall(mystring)
>
> #CODE END

regex = re.compile("[\$]+\w*",re.IGNORECASE)

>>> import re
>>>
>>> mystring = "This Is An \$EXAMPLE\String;"
>>> regex = re.compile("[\$]+\w*",re.IGNORECASE)
>>> keys = regex.findall(mystring)
>>> keys
['$EXAMPLE']
>>> 


Be seeing you,
-- 
Godoy. <[EMAIL PROTECTED]>
-- 
http://mail.python.org/mailman/listinfo/python-list


RE: Regular Expression Problem...

2004-12-01 Thread Doran_Dermot
You could try the following:
regex = re.compile("[\$]\w+", re.IGNORECASE)

I've only done a bit of testing.  Maybe somebody has a better solution.

Cheers!!

Dermot. 

-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of
[EMAIL PROTECTED]
Sent: 01 December 2004 12:23
To: [EMAIL PROTECTED]
Subject: Regular Expression Problem...

Hello NG,

 I am quite new with Python... I'm writing an application that does
also some regexp things on strings, but I'm having problem about
identifying/extracting a substring from another string. What I have to do
is to extract all the strings that begins with a "$" character, but
excluding characters like "." (point) and "'" (single quote) and "\" "/"
(slashes). For example I have:

1) This Is An $EXAMPLE String
2) This Is An $EXAMPLE.String
3) 'This Is An $EXAMPLE'
4) This Is An \$EXAMPLE\String;

I would like to extract only the "keyword" $EXAMPLE and what I'm using at
the moment is:

#CODE BEGIN
import re

mystring = "This Is An \$EXAMPLE\String;"
regex = re.compile("[\$]+\S*",re.IGNORECASE)
keys = regex.findall(mystring)

#CODE END

Obviously this code returns things like $EXAMPLE', $EXAMPLE/, $EXAMPLE. and
so on...
Does anyone have a suggestion?

Thank you a lot.

Andrea.


--

Message for the recipient only, if received in error, please notify the
sender and read http://www.eni.it/disclaimer/

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


Re: Help With Hiring Python Developers

2004-12-01 Thread Bill McClain
On 2004-12-01, fuego <[EMAIL PROTECTED]> wrote:
> My company (http://primedia.com/divisions/businessinformation/) has
> two job openings that we're having a heckuva time filling. 

Allow offsite workers and you'll have all the candidates you want.

-Bill
-- 
Sattre PressThe King in Yellow
http://sattre-press.com/ by Robert W. Chambers
[EMAIL PROTECTED] http://sattre-press.com/kiy.html
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Regular Expression Problem...

2004-12-01 Thread Peter Otten
[EMAIL PROTECTED] wrote:

> identifying/extracting a substring from another string. What I have to do
> is to extract all the strings that begins with a "$" character, but
> excluding characters like "." (point) and "'" (single quote) and "\" "/"
> (slashes). For example I have:
> 
> 1) This Is An $EXAMPLE String
> 2) This Is An $EXAMPLE.String
> 3) 'This Is An $EXAMPLE'
> 4) This Is An \$EXAMPLE\String;
> 
> I would like to extract only the "keyword" $EXAMPLE and what I'm using at

Is that what you want?

>>> import re
>>> r = re.compile("[$]\w+")
>>> r.findall("""
... 1) This Is An $EXAMPLE String
... 2) This Is An $EXAMPLE.String
... 3) 'This Is An $EXAMPLE'
... 4) This Is An \$EXAMPLE\String;
... """)
['$EXAMPLE', '$EXAMPLE', '$EXAMPLE', '$EXAMPLE']

Peter

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


RE: 2.4 or 2.3.4 for 2.3 software?

2004-12-01 Thread Batista, Facundo
Title: RE: 2.4 or 2.3.4 for 2.3 software?





[Jens Bloch Helmers]


#- Can we expect the current release of 2.4 to be just as reliable as
#- 2.3.4 for 2.3 compliant software?


Actually, you can expect to be more reliable, a lot of bugs were fixed.


.   Facundo



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

Re: decorators ?

2004-12-01 Thread Jacek Generowicz
BJörn Lindqvist <[EMAIL PROTECTED]> writes:

> I think the essence of decorators is that it makes it possible to do
> in Python what you in other languages do with method qualifiers.

I find it fascinating that the addition of a bit of syntax sugar gives
the perception that a whole range of new and previously unthinkable
possibilities have opened themselves before us.

@X
def Y...
...


is merely syntax sugar (or syntax ammonia, for some) for


def Y...
...
Y = X(Y)

Anything you can do with decorators, you could do before (with the
exception of rebinding the __name__ of functions).

And yet, that bit of syntax sugar really _does_ make a big difference
to the lengths that people are prepared to take the possibilities that
the underlying feature affords them.
-- 
http://mail.python.org/mailman/listinfo/python-list


Setting namespace using SOAPpy

2004-12-01 Thread Nello Polesello
I'm trying to use a Web Service written in C# from Python (using SOAPpy),
and I don't know how to set namespace.
I'd like to add the attribute xmlns="http://www.uniud.it/email/"; in the tag
 or in my method tag .

I don't want the syntax http://servizi.amm.uniud.it/email/";> used by SOAPpy because it
does not work with the Web Service I want to use.
Is there any method (perhaps in the SOAPpy.Config) that I can use?

Thank you in advance.

-- 
Nello Polesello


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


Semaphore or what should I use?

2004-12-01 Thread Bastian Hammer
Hi

I´m wondering why there are so few examples with Semaphore.
Is it obsolete?

I´ve got a Class Data.
It offers 2 Threads methods for updating, editing, .. a private
dictionary.

Now I have to make sure, that both threads are synchronal, 
1 thread edits something and the other is blocked until the first
thread is ready.

Isn´t it a good idea to do this with a semaphore?

And if I should use a Semaphore here, could anybody give me an example
how it should look like?

Everything that I test throws errors :(

Thank you :)
Bye, Bastian
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Help With Hiring Python Developers

2004-12-01 Thread Skip Montanaro

fuego> We've posted at Monster, Dice, jobs.perl.org and
fuego> python.jobmart.com.  Can anyone advise other job boards that
fuego> might be helpful?

http://www.python.org/Jobs-howto.html

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


Regexp question

2004-12-01 Thread Philippe C. Martin
I realize this is more a regexp question than a python question, but maybe one 
of the re object could help me:

I have wish to know how to _no_ match:

This is but an example of the data I handle:

xx xx xx xx xx xx xx [yy yy yy yy yy yy yy] (zz zz zz zz)

I currently can retrieve the three group of logical data blocks with:

l_str = 'xx xx xx xx xx xx xx [yy yy yy yy yy yy yy] (zz zz zz zz)'
p = re.compile(r'([a-f-0-9\s]*) (\[[a-f-0-9\s]*\]) 
(\([a-f-0-9\s]*\))',re.IGNORECASE) #OK
g = p.search(l_str)


What I would rather do is.

"get the data block that is _not_ between brackets or parenthesis  i.e; 'xx xx 
xx xx xx xx xx' knowing that the intial string could be:

[yy yy yy yy yy yy yy]  xx xx xx xx xx xx xx  (zz zz zz zz)


Any clue  ?

Regards,

Philippe






-- 
*
Philippe C. Martin
SnakeCard LLC
www.snakecard.com
*
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: 2.4 or 2.3.4 for 2.3 software?

2004-12-01 Thread Peter Hansen
Jens Bloch Helmers wrote:
Can we expect the current release of 2.4 to be just as reliable as
2.3.4 for 2.3 compliant software?
Yes, you can expect it.
Whether it *will be* just as reliable is of course a different
story.
The best way to find out is to install it and use it with
your 2.3 software.  Of course, you already did that during
the beta period, right?  ;-)
-Peter
--
http://mail.python.org/mailman/listinfo/python-list


Re: IMAP UTF-7, any codec for that anywhere?

2004-12-01 Thread Jp Calderone
On Wed, 01 Dec 2004 10:35:59 +0100, Max M <[EMAIL PROTECTED]> wrote:
>Brian Quinlan wrote:
>  > Max M wrote:
>  >
>  >> Is there any codec available for handling The special UTF-7 codec for
>  >> IMAP?
> 
>  > Is there something special do you need or is recipe OK?
>  >
>  >  >>> u"\u00ff".encode('utf-7')
>  > '+AP8-'
> 
> 
> A recipe would be excellent. Unfortunately yours is no right. It should 
> have looke like:
> 
>  >>> imapUTF7Encode(u"\u00ff")
> '&AP8-'
> 
> I believe you missed the 'special' in "The special UTF-7 codec for IMAP?"
> 
> Imap folders use a non-standard version of utf-7, where some characters 
> are different.
> 
> I found som messages from 2001 on the net between a few Python unicode 
> developers, where they discuss implementing it. But I cannot find an 
> implementation anywhere.
> 
> I found a perl module that converts to/from the codec, but as usual that 
> is regex hell. Well ok its not that difficult, but I still need to think 
> to hard to parse Perl regex'

  Twisted's IMAP4 support includes an implementation of this codec.  Most of 
the API also happily accepts unicode objects and encodes them as necessary, too.

http://www.twistedmatrix.com/

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


Re: decorators ?

2004-12-01 Thread Skip Montanaro

Jacek> Anything you can do with decorators, you could do before (with
Jacek> the exception of rebinding the __name__ of functions).

And while that feature was added because we realized it would be nice if the
decorated function could have the same name as the original function, it
seems like that change could stand on its own merits.

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


Re: RELEASED Python 2.4 (final)

2004-12-01 Thread Anthony Baxter
On 30 Nov 2004 12:09:37 -0800, Chang LI <[EMAIL PROTECTED]> wrote:.
> > On behalf of the Python development team and the Python community, I'm
> > happy to announce the release of Python 2.4.
> >
> 
> Is there Windows 64-bit edition available?

If you went to the 2.4 page, you'd see that there is indeed a windows-itanium
version available. One click. http://www.python.org/2.4/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Semaphore or what should I use?

2004-12-01 Thread Jeremy Jones
Bastian Hammer wrote:
Hi
I´m wondering why there are so few examples with Semaphore.
Is it obsolete?
I´ve got a Class Data.
It offers 2 Threads methods for updating, editing, .. a private
dictionary.
Now I have to make sure, that both threads are synchronal, 
1 thread edits something and the other is blocked until the first
thread is ready.

Isn´t it a good idea to do this with a semaphore?
And if I should use a Semaphore here, could anybody give me an example
how it should look like?
Everything that I test throws errors :(
Thank you :)
Bye, Bastian
 

Sure, you can use a Semaphore.  But it sounds like you are really 
wanting an exclusive lock.  Semaphore can do that for you - actually 
it's the default behavior.  You could try using a regular old Lock.  
Semaphores are locking counters.  You set the counter at initialization 
to some number (the default is 1).  When you enter into a  semaphored 
area of code (using the .acquire() method), the counter attempts to 
decrement and will do so if it doesn't push it beneath 0.  Upon exiting 
the area of semaphored code (by calling the .release() method on the 
semaphore), the counter is incremented.  An example would look like this:

import threading
class locking_writer:
   def __init__(self, some_file):
   self.sema = threading.Semaphore()
   self.f = open(some_file, 'w')
   def write(self, content):
   self.sema.acquire()
   self.f.write(content)
   self.sema.release()
and used like this:
In [16]: l = locking_writer('/tmp/foo')
In [17]: l.write('test')
I haven't tested this with multiple threads, so I'll leave that up to 
you if you want to use it.

Now, with all that said, the preferred way of synchronizing between 
threads is to use a Queue (import Queue\nq = Queue.Queue()).  If you 
have a file that more than one thread needs to update, you probably want 
to create a thread just to update that file and have the threads 
responsible for getting information to update it with pass that 
information into a queue.  You may have reasons for not wanting to do 
that, but it's worth looking into and considering.

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

Re: Regexp question

2004-12-01 Thread Miki Tebeka
Hello Philippe,

> What I would rather do is.
> 
> "get the data block that is _not_ between brackets or parenthesis  i.e; 'xx 
> xx 
> xx xx xx xx xx' knowing that the intial string could be:
See http://docs.python.org/lib/re-syntax.html and search for "negative
lookahead"

HTH.
--

Miki Tebeka <[EMAIL PROTECTED]>
http://tebeka.spymac.net
The only difference between children and adults is the price of the toys
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Struggling with struct.unpack() and "p" format specifier

2004-12-01 Thread Geoffrey
Thanks for your response.

I guess the documentation on the p format wasn't clear to me ... or
perhaps I was just hoping to much for an easy solution !

The data is part of a record structure that is written to a file with
a few "int"'s and "longs" mixed in.  The pattern repeats through the
file with sometime up to 2500 repititions.

Clearly I can create a subroutine to read the records and extract out
the fields.  I was just hoping I could use the "struct" module and
create a pattern like 'LLHpHLpppH' which would unpack the date and
automatically give me the strings without needing to first determine
their lengths as the length is already embedded in the data.

Any suggestion on how to go about proposing the ability to read
variable length strings based on the preceeding byte value to the
struct module ?  It seems it would be a valuable addition, helping
with code clarity, readability and saving quite a few lines of code -
well atleast me anyways !

Thanks again.

Peter Hansen <[EMAIL PROTECTED]> wrote in message news:<[EMAIL PROTECTED]>...
> Geoffrey wrote:
> > As I mentioned, I can parse the string and read it with multiple
> > statements, I am just looking for a more efficient solution.
> 
> This looks like about the best you can do, using the information
> from Tim's reply:
> 
>  >>> buf = '\0\0\xb9\x02\x13EXCLUDE_CREDIT_CARD'
>  >>> import struct
>  >>> x = struct.unpack('>xxBB%sp' % (ord(buf[4])+1), buf)
>  >>> x
> (185, 2, 'EXCLUDE_CREDIT_CARD')
> 
> If you wanted to avoid hard-coding the 4, you would
> be most correct to do this:
> 
> header = '>xxBB'
> lenIndex = struct.calcsize(header)
> x = struct.unpack('%s%dp' % (header, ord(buf[lenIndex])+1), buf)
> 
> ... though that doesn't exactly make it all that readable.
> 
> -Peter
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Semaphore or what should I use?

2004-12-01 Thread Ville Vainio
> "Bastian" == Bastian Hammer <[EMAIL PROTECTED]> writes:

Bastian> Now I have to make sure, that both threads are
Bastian> synchronal, 1 thread edits something and the other is
Bastian> blocked until the first thread is ready.

Bastian> Isn´t it a good idea to do this with a semaphore?

Semaphore will do, but this is a classical use case for
threading.Lock.

There should be lots of stuff regarding locks (or more googleably,
"mutexes") on the net.

-- 
Ville Vainio   http://tinyurl.com/2prnb
-- 
http://mail.python.org/mailman/listinfo/python-list


A little threading problem

2004-12-01 Thread Alban Hertroys
Hello all,
I need your wisdom again. I'm working on a multi-threaded application 
that handles multiple data sources in small batches each time. The idea 
is that there are 3 threads that run simultaneously, each read a fixed 
number of records, and then they wait for eachother. After that the main 
thread does some processing, and the threads are allowed to continue 
reading data.

I summarized this part of the application in the attached python script, 
which locks up rather early, for reasons that I don't understand (I 
don't have a computer science education), and I'm pretty sure the 
problem is related to what I'm trying to fix in my application. Can 
anybody explain what's happening (Or maybe even show me a better way of 
doing this)?

Regards,
Alban Hertroys,
MAG Productions.
import sys
import threading

class AThread(threading.Thread):
	def __init__(self, name, mainCond, allowedCond):
		self.counter	= 0
		self.name		= name
		self.mainCond	= mainCond
		self.condAllowed = allowedCond
		self.waitUntilRunning = threading.Condition()

		threading.Thread.__init__(self, None, None, name, [])

	def start(self):
		threading.Thread.start(self)

		# Let the main thread wait until this thread is ready to accept Notify
		# events.
		self.waitUntilRunning.acquire()
		self.waitUntilRunning.wait()
		self.waitUntilRunning.release()

	def run(self):
		threading.Thread.run(self)

		# Print numbers 1 - 25
		while self.counter < 25:
			self.condAllowed.acquire()

			# Tell the main thread that we're ready to receive Notifies
			self.waitUntilRunning.acquire()
			self.waitUntilRunning.notify()
			print "Running"
			self.waitUntilRunning.release()

			# Wait for a Notify from the main thread
			print "Wait"
			self.condAllowed.wait()
			self.condAllowed.release()

			self.counter += 1

			print "Thread %s: counter = %d" % (self.name, self.counter)


			# Tell the main thread that a thread has reached the end of the loop
			self.mainCond.acquire()
			self.mainCond.notify()
			self.mainCond.release()

class Main(object):
	def __init__(self):
		self.condWait = threading.Condition()
		self.condAllowed = threading.Condition()

		self.threads = [
			AThread('A', self.condWait, self.condAllowed),
			AThread('B', self.condWait, self.condAllowed),
			AThread('C', self.condWait, self.condAllowed),
		]

		# Start the threads
		for thread in self.threads:
			thread.start()

		while True:
			# Allow the threads to run another iteration
			self.condAllowed.acquire()
			print "Notify"
			self.condAllowed.notifyAll()
			self.condAllowed.release()

			# Wait until all threads reached the end of their loop
			for thread in self.threads:
self.condWait.acquire()
self.condWait.wait()
self.condWait.release()


main = Main()

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

Re: pdb with emacs

2004-12-01 Thread Benjamin Rutt
"Yuri Shtil" <[EMAIL PROTECTED]> writes:

> I am trying to learn python and use the gud/pdb from emacs. The
> functionality that I am used to under gud/gdb and gud/perldb is missing, or
> I don't know how to make it work.
> Specifically: when I start pdb on a script file, the source does not show in
> an another window as it does with perldb and gdb. 

The source appears for me if I do C-c C-s immediately after startup.

> If I bring it up in an another window, the ^X SPC set a break, but
> the subsequent gud-next commands do not move the execution cursor in
> the source file window.

I can in general set breakpoints using C-x SPC in the source buffer
after the source appears, which will be hit after I resume
execution.  So I guess I don't observe your problems.  I am using a
custom "pdb" executable script though, maybe this helps:

#!/bin/sh
exec python $HOME/opt/python-2.3/lib/python2.3/pdb.py "$@"
-- 
Benjamin Rutt
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Syntax for extracting multiple items from a dictionary

2004-12-01 Thread Dave Merrill
"anton muhin" wrote:
> Stefan Behnel wrote:
> >
> >
> > shark schrieb:
> >
> >> row = {"fname" : "Frank", "lname" : "Jones", "city" : "Hoboken",
> >> "state" :
> >> "Alaska"}
> >> cols = ("city", "state")
> >>
> >> Is there a best-practices way to ask for an object containing only the
> >> keys
> >> named in cols out of row? In other words, to get this:
> >> {"city" : "Hoboken", "state" : "Alaska"}
> >
> >
> > Untested:
> >
> > dict( (key,value) for (key,value) in row.iteritems() if key in cols )
> >
> > Works in Py2.4
> >
> > Stefan
>
> Or dict((key, row[key]) for key in cols).
>
> regards,
> anton.

I'm on Py 2.3.3, and neither of these appear to work. Can someone confirm? I
can't see anything in the 2.4 release notes that point to where this would
have changed.

Thanks,

shark


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


Re: Python 2.4 Uninstall Entry in WinXP Registry

2004-12-01 Thread Brad Tilley
Martin v. Löwis wrote:
Brad Tilley wrote:
Python 2.3 placed a registry key under:
'HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Python2.3' 

[...]
Python 2.4 does not use this registry entry on the two machines I have 
installed it on... any tips on how to locate this?

It's under
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{82D9302E-F209-4805-B548-52087047483A} 

which is the product code of Python 2.4. Notice that Python 2.4.1
will use a different product code.
However, if you merely want to avoid that users remove the package,
you can set the ARPNOREMOVE property during installation, e.g.
msiexec /i python24.msi ARPNOREMOVE=1
You might want to set ARPNOMODIFY and ARPNOREPAIR as well.
If you cannot readily pass that property on the command line during
installation, you can use orca.exe (or a python script) to add this
property to the Property table of python24.msi.
If you have W2k or later, you can also set the "NoRemove" registry
value under the key above, to hide the remove feature after
installation.
HTH,
Martin
That's very helpful, thanks Martin! How do I set the install path to 
c:\Program Files?
--
http://mail.python.org/mailman/listinfo/python-list


Re: Syntax for extracting multiple items from a dictionary

2004-12-01 Thread Simon Brunning
On Wed, 1 Dec 2004 10:23:28 -0500, Dave Merrill <[EMAIL PROTECTED]> wrote:
> "anton muhin" wrote:
> > Or dict((key, row[key]) for key in cols).
> 
> I'm on Py 2.3.3, and neither of these appear to work. Can someone confirm? I
> can't see anything in the 2.4 release notes that point to where this would
> have changed.

They use generator expressions, which were introduced by Python 2.4.
See .

-- 
Cheers,
Simon B,
[EMAIL PROTECTED],
http://www.brunningonline.net/simon/blog/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Syntax for extracting multiple items from a dictionary

2004-12-01 Thread Jean Brouwers

The correct syntax is:

dict([(key, row[key]) for key in cols])

i.e. the list must be enclosed in [...].

/Jean Brouwers



In article <[EMAIL PROTECTED]>, Dave Merrill
<[EMAIL PROTECTED]> wrote:

> "anton muhin" wrote:
> > Stefan Behnel wrote:
> > >
> > >
> > > shark schrieb:
> > >
> > >> row = {"fname" : "Frank", "lname" : "Jones", "city" : "Hoboken",
> > >> "state" :
> > >> "Alaska"}
> > >> cols = ("city", "state")
> > >>
> > >> Is there a best-practices way to ask for an object containing only the
> > >> keys
> > >> named in cols out of row? In other words, to get this:
> > >> {"city" : "Hoboken", "state" : "Alaska"}
> > >
> > >
> > > Untested:
> > >
> > > dict( (key,value) for (key,value) in row.iteritems() if key in cols )
> > >
> > > Works in Py2.4
> > >
> > > Stefan
> >
> > Or dict((key, row[key]) for key in cols).
> >
> > regards,
> > anton.
> 
> I'm on Py 2.3.3, and neither of these appear to work. Can someone confirm? I
> can't see anything in the 2.4 release notes that point to where this would
> have changed.
> 
> Thanks,
> 
> shark
> 
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: SOAPpy/ZSI/Twisted SOAP over stdin/stdout?

2004-12-01 Thread Harry George
Harry George <[EMAIL PROTECTED]> writes:

> Normally the SOAP Servers are designed to take control of a port and
> run their own sockets via inheritance from SocktServer.
> 
> But under inetd and xinetd, the port is controlled elsewhere and the
> service just gets the stdin/stdout. I need to configure (or tweak) one
> of the SOAP servers to use that connection.
> 
> Has anyone done this with any of the above named SOAP servers?
> Recommmendations or hints if I try it myself?

First, thanks for the hints - I definitely want to investigate Twisted
"basic".  Second, I've solved it by doing an xinetd "redirect".  Do
external control on one port, then pass the data to an internal-only
port which is watched by the SOAP server.

-- 
[EMAIL PROTECTED]
6-6M21 BCA CompArch Design Engineering
Phone: (425) 294-4718
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: RELEASED Python 2.4 (final)

2004-12-01 Thread Klaus Meyer
Anthony Baxter schrieb:
happy to announce the release of Python 2.4.
Thanks!
minor remarks:
First line from C:\Python24\README.txt
This is Python version 2.4 alpha 3
In C:\Python24\Tools
in various subdirs the README.TXT files disappeared.
--
regards kgm
--
http://mail.python.org/mailman/listinfo/python-list


Re: Question on sorting

2004-12-01 Thread Lad
Peter Otten <[EMAIL PROTECTED]> wrote in message news:<[EMAIL PROTECTED]>...
> Lad wrote:
> 
> > wes weston <[EMAIL PROTECTED]> wrote in message
> > news:<[EMAIL PROTECTED]>...
> >> Lad wrote:
> >> > Hi,
> >> > I have a file of records of 4 fields each.
> >> > Each field is separated by a semicolon. That is
> >> > 
> >> > Filed1;Ffield2;Field3;Field4
> >> > 
> >> > But there may be also empty records such as
> >> > 
> >> > (only semicolons).
> >> > 
> >> > For sorting I used
> >> > #
> >> > lines = file('Config.txt').readlines()# a file I want to sort
> >> > lines.sort()
> >> > ff=open('ConfigSorted.txt','w')# sorted file
> >> > ff.writelines(lines)
> >> > ff.close()
> >> > ###
> >> > It was sorted but empty records were first. I need them to be last(at
> >> > the end of the file). How can I do that?
> >> > 
> >> > Thanks for help
> >> > Lad
> >> 
> >> Lad,
> >> The sort call can have a function name as an arg. You
> >> could do:
> >> 
> >> def mycompare(s1,s2):
> >> #return -1 to put s1's at front; 1 to put s1's at back; 0 for a tie
> >> #if s1=="" and s2<>"": return 1
> >> 
> >> lines.sort(mycompare)
> >> 
> > Wes,
> > Thank you for reply. But I do not understand mycompare function. Can
> > you please explain to me how it should work? Thanks
> 
> compare(a, b) is just a function for comparing two items/lines. I must
> return -1 if ab, and 0 if a==b. For example the following
> compare moves the "" records to the end and keeps the order of others
> unaffected:
> 
> >>> items = ["", ";a;b;;", ";b;a;;", "a;b;c;d;e", "a;;;d;e"]
> >>> def compare(a, b):
> ... return cmp(a == "", b == "") or cmp(a, b)
> ...
> >>> items.sort(compare)
> >>> items
> [';a;b;;', ';b;a;;', 'a;;;d;e', 'a;b;c;d;e', '']
> 
Petr,
thank you for help and explanation.
It works
Lad
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python 2.4 Uninstall Entry in WinXP Registry

2004-12-01 Thread Brad Tilley
Brad Tilley wrote:
Martin v. Löwis wrote:
Brad Tilley wrote:
Python 2.3 placed a registry key under:
'HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Python2.3' 


[...]
Python 2.4 does not use this registry entry on the two machines I 
have installed it on... any tips on how to locate this?

It's under
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{82D9302E-F209-4805-B548-52087047483A} 

which is the product code of Python 2.4. Notice that Python 2.4.1
will use a different product code.
However, if you merely want to avoid that users remove the package,
you can set the ARPNOREMOVE property during installation, e.g.
msiexec /i python24.msi ARPNOREMOVE=1
You might want to set ARPNOMODIFY and ARPNOREPAIR as well.
If you cannot readily pass that property on the command line during
installation, you can use orca.exe (or a python script) to add this
property to the Property table of python24.msi.
If you have W2k or later, you can also set the "NoRemove" registry
value under the key above, to hide the remove feature after
installation.
HTH,
Martin

That's very helpful, thanks Martin! How do I set the install path to 
c:\Program Files?
I found the documentation here:
http://python.fyxm.net/2.4/msi.html
--
http://mail.python.org/mailman/listinfo/python-list


assymetry between a == b and a.__eq__(b) (WAS: pre-PEP generic objects)

2004-12-01 Thread Steven Bethard
Peter Otten wrote:
Steven Bethard wrote:
def __eq__(self, other):
   """x.__eq__(y) <==> x == y"""
   return (isinstance(other, self.__class__)
   and self.__dict__ == other.__dict__)

This results in an asymmetry:
from bunch import Bunch
class B(Bunch): pass
...
B().__eq__(Bunch())
False
Bunch().__eq__(B())
True
With indirect use of __eq__() this puzzling behaviour disappears:
B() == Bunch()
False
Bunch() == B()
False
Whether this is intended, I don't know. If someone can enlighten me...
It does look like it's at least documented:
http://docs.python.org/ref/comparisons.html
"The operators <, >, ==, >=, <=, and != compare the values of two 
objects. The objects need not have the same type. If both are numbers, 
they are converted to a common type. Otherwise, objects of different 
types always compare unequal, and are ordered consistently but arbitrarily."

This sounds like using "==" makes a guarantee that objects of different 
types will compare unequal, while my __eq__ method (using isinstance) 
did not make this guarantee.

I tried to check the C code to verify this (that different classes are 
guaranteed to be unequal) but rich comparisons make that code pretty 
complicated.

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


Drawing Cogwheels and Combinatoric diagrams

2004-12-01 Thread Andrew James
Gentlemen,
I'm looking for a graphing or drawing python package that will allow me 
to draw complex geometric shapes. I need to be able to create shapes 
like cogwheels and Venn diagrams:

http://encyclopedia.thefreedictionary.com/Venn
The library must support alpha blending and the ability to return x,y 
co-ordinates for a shape, as I want to draw an imagemap on top of parts 
of the shape.

Can PIL do this, or do I need to go the way of GnuPlot or Gri? Can 
anyone give me an example of a complex shape drawn like this?

Many thanks,
Andrew
--
http://mail.python.org/mailman/listinfo/python-list


Re: Regexp question

2004-12-01 Thread Mitja
On Wed, 1 Dec 2004 07:48:24 -0600, Philippe C. Martin  
<[EMAIL PROTECTED]> wrote:

I realize this is more a regexp question than a python question, but  
maybe one
of the re object could help me:

I have wish to know how to _no_ match:
This is but an example of the data I handle:
xx xx xx xx xx xx xx [yy yy yy yy yy yy yy] (zz zz zz zz)
I currently can retrieve the three group of logical data blocks with:
l_str = 'xx xx xx xx xx xx xx [yy yy yy yy yy yy yy] (zz zz zz zz)'
p = re.compile(r'([a-f-0-9\s]*) (\[[a-f-0-9\s]*\])
(\([a-f-0-9\s]*\))',re.IGNORECASE) #OK
g = p.search(l_str)
What I would rather do is.
"get the data block that is _not_ between brackets or parenthesis  i.e;  
'xx xx
xx xx xx xx xx' knowing that the intial string could be:

[yy yy yy yy yy yy yy]  xx xx xx xx xx xx xx  (zz zz zz zz)
Any clue  ?
regexps seem an overkill for the task at hand.
If data is really as simple as you suggest, you can try the following:
s = 'xx [y y] (z z)'
s = s[:s.index('(')] + s[s.index(')')+1:]
s
'xx [y y] '
s = s[:s.index('[')] + s[s.index(']')+1:]
s
'xx  '
s.strip()
'xx'
Relevant lines:
s = s[:s.index('(')] + s[s.index(')'):]
s = s[:s.index('[')] + s[s.index(']')+1:]
s = s.strip()
--
Mitja
--
http://mail.python.org/mailman/listinfo/python-list


Converting String to Class

2004-12-01 Thread michael
Hello,

I have a script that is called by the shell this way :

mqtrigger.py "TMC2TEST.QUEUE LV1871.MQPROCESS"

So argv[1] is the string "TMC2TEST.QUEUE LV1871.MQPROCESS"

I would like to construct a class with that string that contains the
attributes

-StrucId
-VersionId
-QName
-ProcessName

I am thinking about using the following info

opts = [['StrucId', CMQC.MQTMC_STRUC_ID, '4s'],   
['Version', CMQC.MQTMC_VERSION_2, '4s'],
['QName', '', '48s'],   ## or less :-)
['ProcessName', '', '48s']] ## or less :-)

1. is the attributename
2. is the default
3. is the format in the string

So the string could be parsed with the opts Info and the attributes
could be inserted into the class. I dont even have a starting point
how to do that. Could somebody point my into the right direction

Regards

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


Re: A little threading problem

2004-12-01 Thread Jeremy Jones




Alban Hertroys wrote:
Hello
all,
  
  
I need your wisdom again. I'm working on a multi-threaded application
that handles multiple data sources in small batches each time. The idea
is that there are 3 threads that run simultaneously, each read a fixed
number of records, and then they wait for eachother. After that the
main thread does some processing, and the threads are allowed to
continue reading data.
  
  
I summarized this part of the application in the attached python
script, which locks up rather early, for reasons that I don't
understand (I don't have a computer science education), and I'm pretty
sure the problem is related to what I'm trying to fix in my
application. Can anybody explain what's happening (Or maybe even show
me a better way of doing this)?
  
  
Regards,
  
  
Alban Hertroys,
  
MAG Productions.
  
  

import sys
import threading

class AThread(threading.Thread):
	def __init__(self, name, mainCond, allowedCond):
		self.counter	= 0
		self.name		= name
		self.mainCond	= mainCond
		self.condAllowed = allowedCond
		self.waitUntilRunning = threading.Condition()

		threading.Thread.__init__(self, None, None, name, [])

	def start(self):
		threading.Thread.start(self)

		# Let the main thread wait until this thread is ready to accept Notify
		# events.
		self.waitUntilRunning.acquire()
		self.waitUntilRunning.wait()
		self.waitUntilRunning.release()

	def run(self):
		threading.Thread.run(self)

		# Print numbers 1 - 25
		while self.counter < 25:
			self.condAllowed.acquire()

			# Tell the main thread that we're ready to receive Notifies
			self.waitUntilRunning.acquire()
			self.waitUntilRunning.notify()
			print "Running"
			self.waitUntilRunning.release()

			# Wait for a Notify from the main thread
			print "Wait"
			self.condAllowed.wait()
			self.condAllowed.release()

			self.counter += 1

			print "Thread %s: counter = %d" % (self.name, self.counter)


			# Tell the main thread that a thread has reached the end of the loop
			self.mainCond.acquire()
			self.mainCond.notify()
			self.mainCond.release()

class Main(object):
	def __init__(self):
		self.condWait = threading.Condition()
		self.condAllowed = threading.Condition()

		self.threads = [
			AThread('A', self.condWait, self.condAllowed),
			AThread('B', self.condWait, self.condAllowed),
			AThread('C', self.condWait, self.condAllowed),
		]

		# Start the threads
		for thread in self.threads:
			thread.start()

		while True:
			# Allow the threads to run another iteration
			self.condAllowed.acquire()
			print "Notify"
			self.condAllowed.notifyAll()
			self.condAllowed.release()

			# Wait until all threads reached the end of their loop
			for thread in self.threads:
self.condWait.acquire()
self.condWait.wait()
self.condWait.release()


main = Main()

  

You've got a deadlock.  I modified your script to add a print "T-%s" %
self.name before an acquire and after a release in the threads you spun
off (not in the main thread).  Here is the output:

[EMAIL PROTECTED] threading]$ python tt.py
T-A: acquiring condAllowed
T-A: acquiring waitUntilRunning
T-A: Running
T-A: released waitUntilRunning
T-A: Wait
T-B: acquiring condAllowed
T-B: acquiring waitUntilRunning
T-B: Running
T-B: released waitUntilRunning
T-B: Wait
T-C: acquiring condAllowed
T-C: acquiring waitUntilRunning
T-C: Running
T-C: released waitUntilRunning
T-C: Wait
Notify
T-A: released condAllowed
T-A: counter = 1
T-A: acquiring mainCond
T-A: released mainCond
T-A: acquiring condAllowed
T-A: acquiring waitUntilRunning
T-A: Running
T-A: released waitUntilRunning
T-A: Wait
T-C: released condAllowed
T-C: counter = 1
T-C: acquiring mainCond
T-C: released mainCond
T-C: acquiring condAllowed
T-C: acquiring waitUntilRunning
T-C: Running
T-C: released waitUntilRunning
T-C: Wait
T-B: released condAllowed
T-B: counter = 1
T-B: acquiring mainCond
T-B: released mainCond
T-B: acquiring condAllowed
Notify <-Here is
your problem
T-A: released condAllowed
T-A: counter = 2
T-A: acquiring mainCond
T-A: released mainCond
T-A: acquiring condAllowed
T-A: acquiring waitUntilRunning
T-A: Running
T-A: released waitUntilRunning
T-A: Wait
T-B: acquiring waitUntilRunning
T-B: Running
T-B: released waitUntilRunning
T-B: Wait
T-C: released condAllowed
T-C: counter = 2
T-C: acquiring mainCond
T-C: released mainCond
T-C: acquiring condAllowed
T-C: acquiring waitUntilRunning
T-C: Running
T-C: released waitUntilRunning
T-C: Wait

Notify is called before thread B (in this case) hits the
condAllowed.wait() piece of code.  So, it sits at that wait() for
forever (because it doesn't get notified, because the notification
already happened), waiting to be notified from the main thread, and the
main thread is waiting on thread B (again, in this case) to call
mainCond.notify().  This approach is a deadlock just wanting to happen
(not waiting, because it already did happen).  What is it exactly that
you are trying to accomplish?  I'm sure there is a

Re: Syntax for extracting multiple items from a dictionary

2004-12-01 Thread Peter Hansen
Dave Merrill wrote:
"anton muhin" wrote:
Or dict((key, row[key]) for key in cols).
I'm on Py 2.3.3, and neither of these appear to work. 
You're probably getting the error shown.  Try the change in
the line following it instead.
Python 2.3.4 (#53, May 25 2004, 21:17:02) [MSC v.1200 32 bit (Intel)]
>>> row = {'fname': 'Frank', 'lname': 'Jones', 'city': 'Hoboken', 
'state': 'Alaska'}
>>> cols = ['city', 'state']
>>> dict((key, row[key]) for key in cols)
  File "", line 1
dict((key, row[key]) for key in cols)
   ^
SyntaxError: invalid syntax
>>> dict([(key, row[key]) for key in cols])
{'city': 'Hoboken', 'state': 'Alaska'}


I can't see anything in the 2.4 release notes that point to where this would
have changed.
See http://www.python.org/2.4/highlights.html and search for
"generator expressions".
-Peter
--
http://mail.python.org/mailman/listinfo/python-list


Python xmlrpc servers?

2004-12-01 Thread ted holden

I have a project for which being able to write xmlrpc server code in python
would be vastly preferable to the second choice solution for a number of
reasons.  Unfortunately, pretty much everything I see on the net in the way
of documentation appears either insufficient or outdated.

The example given in the Python documentation for  SimpleXMLRPCServer is
more or less incomprehensible.  That example is as follows:

class MyFuncs:
   def div(self, x, y) : return div(x,y)

handler = CGIXMLRPCRequestHandler()
handler.register_function(pow)
handler.register_function(lambda x,y: x+y, 'add')
handler.register_introspection_functions()
handler.register_instance(MyFuncs())
handler.handle_request()

I don't see where the "div(x,y)" which is returned in the class function
definition comes from.  I don't see any relationship between the class
MyFuncs and the rest of the program.  I don't see where the returned
function "pow" comes from or what its relevance is.  I don't see what
"lambda" is or how a lambda function is supposed to be construed as adding
two numbers together.  I don't see how this server is supposed to be used.

I also find an example written by Dave Warner:

http://www.onlamp.com/pub/a/python/2001/01/17/xmlrpcserver.html

which is about four years old and dated.  In particular, the include file 
xmlrpcserver which he imports no longer exists.

And then, I find one example in an IBM reference which actually does work as
stated on a single computer:

http://www-106.ibm.com/developerworks/webservices/library/ws-pyth10.html

The test client provided looks like:

mport xmlrpclib

server = xmlrpclib.ServerProxy("http://localhost:";)
month = server.getMonth(2002, 8)
print month


which actually works.  Nonetheless I need this thing to work across
machines.  I have a primitive network here usingVerizon DMS and a Linksys
router which sees the three computers on it as 192.168.1.100,
192.168.1.101, and 192.168.1.102 as usual. 

Question is, what does it take to run the server on 102 and a client on 100?

Changing the obvious line in the client program to:

server = xmlrpclib.ServerProxy("http://192.168.1.102:";)

doesn't work.  Aside from that, I'd like to get the CGI version of the thing
which uses .py files in the CGI bin to work as well and again the only
example I see of that (in the Python documentation) is undecipherable. 

I'd appreciate any suggestions or info anybody might have.








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


Python 3000 and "Python Regrets"

2004-12-01 Thread beliavsky
I just came across the slides for Guido van Rossum's "Python Regrets"
talk, given in 2002. It worries me that much of my Python code would
be broken if all of his ideas were implemented. He doesn't even like
'print'. Of course, I am not qualified to argue with Van Rossum about
the direction of Python.

When is Python "3000" expected to appear? Is there a list of expected
incompatibilities with Python 2.3? Are serious Python programmers
already taking care to avoid using Python features that may disappear
in Python 3000?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Help With Hiring Python Developers

2004-12-01 Thread Miklós P
"fuego" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> My company (http://primedia.com/divisions/businessinformation/) has
> two job openings that we're having a heckuva time filling.  We've
> posted at Monster, Dice, jobs.perl.org and python.jobmart.com.  Can
> anyone advise other job boards that might be helpful?  Also, feel free
..
> Thanks in advance!

Hm, you're looking for *Manhattan locals* who are required to have Perl
skills (i.e. magically working, hardly readable line noise :D ) but
optionally they may have Python skills, too (i.e. magically working, easily
readable pseudo code :D )

How about adding the additional requirement of COBOL and that the applicant
must live in a particular street? :-)

Miklós



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


Re: Python 3000 and "Python Regrets"

2004-12-01 Thread Ian Bicking
[EMAIL PROTECTED] wrote:
I just came across the slides for Guido van Rossum's "Python Regrets"
talk, given in 2002. It worries me that much of my Python code would
be broken if all of his ideas were implemented. He doesn't even like
'print'. Of course, I am not qualified to argue with Van Rossum about
the direction of Python.
When is Python "3000" expected to appear? Is there a list of expected
incompatibilities with Python 2.3? Are serious Python programmers
already taking care to avoid using Python features that may disappear
in Python 3000?
Python 3000 is kind of imaginary.  It's a what-if: what if Guido could 
do whatever he wanted without worrying about backward compatibility?

At one point Python 3000 and Python 3.0 were kind of the same thing (or 
the same plan -- neither are implemented or even thoroughly planned). 
Now they are separate ideas -- if you see references to Python 3.0, it 
also includes some backward incompatible changes and cleanup, like maybe 
input() will disappear, and integer division will go away, and things 
like range() will return iterators (and xrange goes away).  But it's 
much more conservative, and presented as a more realistic plan.  print 
will still be around.

--
Ian Bicking  /  [EMAIL PROTECTED]  /  http://blog.ianbicking.org
--
http://mail.python.org/mailman/listinfo/python-list


Re: Python xmlrpc servers?

2004-12-01 Thread Skip Montanaro

ted> The example given in the Python documentation for
ted> SimpleXMLRPCServer is more or less incomprehensible.  

Agreed, there is a doc fix needed.  Try mentally adding

from math import *

to the start of the example.  That will get you the pow function.  It's
still incorrect though.  There's no div function, either builtin or in the
math module.  The MyFuncs class should be defined as in the 2.4 docs:

class MyFuncs:
def div(self, x, y) : return x // y

ted> I don't see any relationship between the class MyFuncs and the rest
ted> of the program.

In this simpleminded example, there is none.  The goal of the example is to
show how the register_* methods are used.  In a real-life application any
instances registered would probably store considerable parts of the
application state or be able to communicate with those objects that do.

ted> I don't see what "lambda" is or how a lambda function is supposed
ted> to be construed as adding two numbers together.

Lambda is a keyword in Python used to create and return very simple
(single-expression) functions.  Lambda expressions can be used anywhere
you'd normally use a function object.  See:

http://www.python.org/doc/current/ref/lambdas.html

The line containing the lambda expression:

server.register_function(lambda x,y: x+y, 'add')

could be recast as:

def add(x, y):
return x+y

server.register_function(add, 'add')

though the second arg isn't required since it matches the function's
__name__ attribute.  It's required when a lambda expression is used though
because lambda expressions don't have terribly useful __name__ attributes:

>>> f = lambda x,y: x+y
>>> f
 at 0x65c970>
>>> f.__name__
''
>>> def add(x,y):
...   return x+y
... 
>>> add.__name__
'add'

ted> And then, I find one example in an IBM reference which actually
ted> does work as stated on a single computer:
...
ted> which actually works.  Nonetheless I need this thing to work across
ted> machines.

The server listens to "localhost" on port .  To allow it to listen for
external connections change "localhost" to the name or IP address of the
server.  Before you do that make sure you understand the ramifications of
exposing your XML-RPC server to a broader class of potential clients, some
of which are bound to be malicious.

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


Re: Python 3000 and "Python Regrets"

2004-12-01 Thread Tim Peters
[EMAIL PROTECTED]
> I just came across the slides for Guido van Rossum's "Python
> Regrets" talk, given in 2002. It worries me that much of my Python
> code would be broken if all of his ideas were implemented.

Actually, none of it would break, provided you don't change the Python
implementation you use.

> He doesn't even like 'print'. Of course, I am not qualified to argue
> with Van Rossum about the direction of Python.
>
> When is Python "3000" expected to appear?

This is usually expressed an as a positive offset from the time hell
freezes over, but people vary in their estimation of both parts.  At a
minimum, it requires that Guido first get a job where he can
concentrate on Python development.  That will happen when hell freezes
over, but may happen before then.  Hard to say.

> Is there a list of expected incompatibilities with Python 2.3?

No.

> Are serious Python programmers already taking care to avoid
> using Python features that may disappear in Python 3000?

No, although some naturally avoid dubious features without being
threatened .
-- 
http://mail.python.org/mailman/listinfo/python-list


non blocking read()

2004-12-01 Thread Uwe Mayer
Hi,

I use select() to wait for a file object (stdin) to become readable. In that
situation I wanted to read everything available from stdin and return to
the select statement to wait for more.

However, the file object's read method blocks if the number of bytes is 0 or
negative. 

Is there no way to read everything a channel's got currently got without
blocking?

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


Re: module imports and memory usage

2004-12-01 Thread Carlos Ribeiro
On Tue, 30 Nov 2004 16:46:43 -0500, Brad Tilley <[EMAIL PROTECTED]> wrote:
> I discovered that when I wrap my code up in a function def and call it
> that it uses around 4.6 MB of RAM all the time... even while sleeping.
> However, when I don't put it in a function def it uses around 2.6MB of
> data when it executes and only 100KB while sleeping. Why is this?

Totally unchecked, popped up from somewhere between my ears.

Is it possible that (in some situations) the function object keeps a
reference to its locals() somewhere, in such a way that it never gets
collected? Just wondering...


-- 
Carlos Ribeiro
Consultoria em Projetos
blog: http://rascunhosrotos.blogspot.com
blog: http://pythonnotes.blogspot.com
mail: [EMAIL PROTECTED]
mail: [EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python xmlrpc servers?

2004-12-01 Thread ted holden
Skip Montanaro wrote:


> ted> I don't see what "lambda" is or how a lambda function is supposed
> ted> to be construed as adding two numbers together.
> 
> Lambda is a keyword in Python used to create and return very simple
> (single-expression) functions.  Lambda expressions can be used anywhere
> you'd normally use a function object.  See:
> 
> http://www.python.org/doc/current/ref/lambdas.html
> 
> The line containing the lambda expression:
> 
> server.register_function(lambda x,y: x+y, 'add')
> 
> could be recast as:
> 
> def add(x, y):
> return x+y
> 
> server.register_function(add, 'add')

That's a whole lot easier to digest.  I'd have assumed lambda was some sort
of stat function...


> The server listens to "localhost" on port .  To allow it to listen for
> external connections change "localhost" to the name or IP address of the
> server.  Before you do that make sure you understand the ramifications of
> exposing your XML-RPC server to a broader class of potential clients, some
> of which are bound to be malicious.
> 
> Skip


Many thanks, that's the part I was missing in the case of standalone
servers.  The only other real question is what about the cgi servers?  I'd
assume I'd take the example given:

class MyFuncs:
def div(self, x, y) : return div(x,y)

handler = CGIXMLRPCRequestHandler()
handler.register_function(pow)
handler.register_function(lambda x,y: x+y, 'add')
handler.register_introspection_functions()
handler.register_instance(MyFuncs())
handler.handle_request()

Stuff that into a file in the cgi-bin dir on the server, and then try to use
something like: 


server = xmlrpclib.Server("http://192.168.1.102/testserver.py";)
or
server = xmlrpclib.Server("http://192.168.1.102/cgi-bin/testserver.py";)


That still hasn't worked, so far at least.










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


Re: Python xmlrpc servers?

2004-12-01 Thread Skip Montanaro

ted> Would several web services on the same server listen on different
ted> ports (, 8889, 8890...) or on the same port?

Port numbers are never implicit.  You need to provide a listen port each
time you start the server.

Skip


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


Re: Python xmlrpc servers?

2004-12-01 Thread Skip Montanaro
ted> The only other real question is what about the cgi servers?  I'd
ted> assume I'd take the example given:

ted> class MyFuncs:
ted> def div(self, x, y) : return div(x,y)

ted> handler = CGIXMLRPCRequestHandler()
ted> handler.register_function(pow)
ted> handler.register_function(lambda x,y: x+y, 'add')
ted> handler.register_introspection_functions()
ted> handler.register_instance(MyFuncs())
ted> handler.handle_request()

ted> Stuff that into a file in the cgi-bin dir on the server, and then
ted> try to use something like:

ted> server = xmlrpclib.Server("http://192.168.1.102/testserver.py";)
ted> or
ted> server = xmlrpclib.Server("http://192.168.1.102/cgi-bin/testserver.py";)

ted> That still hasn't worked, so far at least.

I've never used XML-RPC in a CGI context before.  Have you looked in your
web server's error log file?

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


Re: pickle and py2exe

2004-12-01 Thread Johan Lindberg
> Im trying to compile a script with py2exe. The pickle module is causing the
> program to give an error.
> 
> Traceback (most recent call last):
>   File "SETIstat.pyw", line 330, in ?
>   File "SETIstat.pyw", line 84, in start_up
>   File "SETIstat.pyw", line 79, in config_load
>   File "pickle.pyc", line 1390, in load
>   File "pickle.pyc", line 872, in load
>   File "pickle.pyc", line 985, in load_string
> LookupError: unknown encoding: string-escape
> 
> the data in the pickled file is a dictionary containing a couple strings. The
> strings do contain \n and \t charaters but no other special characters or
> anything. 
> 
> Does anyone have any suggestions to what I can try to get around this? The
> pickle module works fine when the .pyw file is run. Its only when I compile
> this is there an issue. 
> 
> Thanks for any help,
> 
> Justin

Have you included string-escape encoding in your setup.py?
My guess is that you can fix the problem with something similar to:

 from distutils.core import setup
 import py2exe
 opts = { "py2exe": { "packages": ["encodings"], } }
 setup(windows= ["spam.py"], options= opts)

in your setup.py.

Hope it helps
/Johan Lindberg
-- 
http://mail.python.org/mailman/listinfo/python-list


Python Win32 Silent Install

2004-12-01 Thread Matt Gerrans
Looks like the installer for the Win32 extensions has changed from Wise to 
distutils, so now my automated silent installations don't work anymore. 
Anyone know if the distutils binary installer can be run silently?I 
haven't been able find a command line reference for distutils binaries (I'm 
still sifting through http://www.python.org/doc/current/dist/, though...).

Maybe there is a better way to do an unattended install of the Win32 
extensions (that is, perhaps without using the binary)?

Anyway, I'm looking into this on the python.org and starship pages, but I 
just thought I'd see if anyone can point me in the right direction...

- Matt 


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


Re: Python xmlrpc servers?

2004-12-01 Thread Jaime Wyant
Mark Pilgrim wrote a really neat piece of python code that did XML-RPC
over CGI.  It seems to have disappeared from his website, though
(http://diveintomark.org/public/webservices.txt).

If you can't dig it up, I have a working copy that I use.  I'll post
it / email it if you want.

jw


On Wed, 1 Dec 2004 13:26:21 -0600, Skip Montanaro <[EMAIL PROTECTED]> wrote:
> ted> The only other real question is what about the cgi servers?  I'd
> ted> assume I'd take the example given:
> 
> ted> class MyFuncs:
> ted> def div(self, x, y) : return div(x,y)
> 
> ted> handler = CGIXMLRPCRequestHandler()
> ted> handler.register_function(pow)
> ted> handler.register_function(lambda x,y: x+y, 'add')
> ted> handler.register_introspection_functions()
> ted> handler.register_instance(MyFuncs())
> ted> handler.handle_request()
> 
> ted> Stuff that into a file in the cgi-bin dir on the server, and then
> ted> try to use something like:
> 
> ted> server = xmlrpclib.Server("http://192.168.1.102/testserver.py";)
> ted> or
> ted> server = 
> xmlrpclib.Server("http://192.168.1.102/cgi-bin/testserver.py";)
> 
> ted> That still hasn't worked, so far at least.
> 
> I've never used XML-RPC in a CGI context before.  Have you looked in your
> web server's error log file?
> 
> Skip
> 
> 
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python 3000 and "Python Regrets"

2004-12-01 Thread Matt Gerrans
Anyway, what's to worry about?When the time comes just whip out a little 
script that converts Python 1.6 (or whatever you like) to Python3K; it will 
only take seven lines of P3K code. 


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


Re: Python xmlrpc servers?

2004-12-01 Thread ted holden
Jaime Wyant wrote:

> Mark Pilgrim wrote a really neat piece of python code that did XML-RPC
> over CGI.  It seems to have disappeared from his website, though
> (http://diveintomark.org/public/webservices.txt).
> 
> If you can't dig it up, I have a working copy that I use.  I'll post
> it / email it if you want.
> 

Thanks, couldn't hurt anything to post it.  Again the real problem seems to
be the cnostant state of flux of open software and the attempts to have
machines and software write documentation don't really seem to help much.


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


Re: non blocking read()

2004-12-01 Thread Jp Calderone
On Wed, 01 Dec 2004 19:39:45 +0100, Uwe Mayer <[EMAIL PROTECTED]> wrote:
>Hi,
> 
> I use select() to wait for a file object (stdin) to become readable. In that
> situation I wanted to read everything available from stdin and return to
> the select statement to wait for more.
> 
> However, the file object's read method blocks if the number of bytes is 0 or
> negative. 
> 
> Is there no way to read everything a channel's got currently got without
> blocking?

def nonBlockingReadAll(fileObj):
bytes = []
while True:
b = fileObj.read(1024)
bytes.append(b)
if len(b) < 1024:
break
return ''.join(bytes)

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


Re: Python Win32 Silent Install

2004-12-01 Thread Thomas Heller
"Matt Gerrans" <[EMAIL PROTECTED]> writes:

> Looks like the installer for the Win32 extensions has changed from Wise to 
> distutils, so now my automated silent installations don't work anymore. 
> Anyone know if the distutils binary installer can be run silently?I 
> haven't been able find a command line reference for distutils binaries (I'm 
> still sifting through http://www.python.org/doc/current/dist/, though...).

There are no command line options for the distutils created installer,
and silent installation is not possible.

> Maybe there is a better way to do an unattended install of the Win32 
> extensions (that is, perhaps without using the binary)?

I should be quite easy to write a Python script that opens the binary as
a zipfile, and then does what the gui does without showing a gui.

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


Re: Converting String to Class

2004-12-01 Thread Matt Gerrans
You didn't specify exactly how the string is parsed, so this is a guess:

class Thingy(object):
   def __init__(self,rawinfo):
  self.StructId, vq,self.ProcessName = rawinfo.split()
  self.Version,self.QName = vq.split('.')
   def __str__(self):
  return '' % (self.StructId, self.Version, self.QName, self.ProcessName)

t = Thingy( "TMC2TEST.QUEUE LV1871.MQPROCESS" )
str(t) -> ''

- mfg 


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


Re: Python xmlrpc servers?

2004-12-01 Thread Skip Montanaro

>> Have you looked in your web server's error log file?

ted> Shoulda thought of that  It's telling me that the name
ted> CGIXMLRPCRequestHandler is not found.  In other words, it is trying
ted> to execute the proper file at least.  I'd have that that importing
ted> SimpleXMLRPCServer would have sufficed to make the right classes
ted> available.

Sounds like you are executing

import SimpleXMLRPCServer

If so, you need to qualify the reference to the handler class like

SimpleXMLRPCServer.CGIXMLRPCRequestHandler

An import statement loads the specified module and binds a variable in the
current scope to the resulting module object.  There's a builtin __import__
function that imports and returns a module object.  The above import
statement is equivalent to

SimpleXMLRPCServer = __import__("SimpleXMLRPCServer")

If you want to import selected names from the module's namespace you can
execute

from SimpleXMLRPCServer import CGIXMLRPCRequestHandler

which creates a binding in the current namespace called
"CGIXMLRPCRequestHandler" associated with that class.

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


Re: Python xmlrpc servers?

2004-12-01 Thread Jaime Wyant
Check these out ->

http://server3.sleekcom.com/~jaime/webservice.html (syntax highlighted version)
http://server3.sleekcom.com/~jaime/webservice.txt (savable text version)

HTH,
jw

On Wed, 01 Dec 2004 20:04:46 GMT, ted holden <[EMAIL PROTECTED]> wrote:
> Jaime Wyant wrote:
> 
> > Mark Pilgrim wrote a really neat piece of python code that did XML-RPC
> > over CGI.  It seems to have disappeared from his website, though
> > (http://diveintomark.org/public/webservices.txt).
> >
> > If you can't dig it up, I have a working copy that I use.  I'll post
> > it / email it if you want.
> >
> 
> Thanks, couldn't hurt anything to post it.  Again the real problem seems to
> be the cnostant state of flux of open software and the attempts to have
> machines and software write documentation don't really seem to help much.
> 
> 
> Ted
> 
> 
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python 3000 and "Python Regrets"

2004-12-01 Thread Brad Tilley
Matt Gerrans wrote:
Anyway, what's to worry about?When the time comes just whip out a little 
script that converts Python 1.6 (or whatever you like) to Python3K; it will 
only take seven lines of P3K code. 


How about 'import classic'
--
http://mail.python.org/mailman/listinfo/python-list


ANN: pyMinGW support for Python 2.4 (final) is available

2004-12-01 Thread A. B., Khalid
This is to inform those interested in compiling Python in MinGW that
an updated version of pyMinGW is now available.


Get it from here:
http://jove.prohosting.com/iwave/ipython/pyMinGW.html


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


M2Crypto for 2.4

2004-12-01 Thread Elbert Lev
People!

Have somebody build M2Crypto for 2.4 on windows? If yes, please tell
if there are any problems.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python xmlrpc servers?

2004-12-01 Thread ted holden
Skip Montanaro wrote:


> If so, you need to qualify the reference to the handler class like
> 
> SimpleXMLRPCServer.CGIXMLRPCRequestHandler

Again thanks, that works.  If I weren't worried about jinxing myself I'd say
I seem to be in pretty good shape at this point...

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


Re: Python 3000 and "Python Regrets"

2004-12-01 Thread Steve Holden
Brad Tilley wrote:
Matt Gerrans wrote:
Anyway, what's to worry about?When the time comes just whip out a 
little script that converts Python 1.6 (or whatever you like) to 
Python3K; it will only take seven lines of P3K code.

How about 'import classic'
... or
from __past__ import __mistakes__
looking-forwards-to-christmas-ly y'rs  - steve
--
http://www.holdenweb.com
http://pydish.holdenweb.com
Holden Web LLC +1 800 494 3119
--
http://mail.python.org/mailman/listinfo/python-list


Re: non blocking read()

2004-12-01 Thread Donn Cave
In article <[EMAIL PROTECTED]>,
 Uwe Mayer <[EMAIL PROTECTED]> wrote:

> Hi,
> 
> I use select() to wait for a file object (stdin) to become readable. In that
> situation I wanted to read everything available from stdin and return to
> the select statement to wait for more.
> 
> However, the file object's read method blocks if the number of bytes is 0 or
> negative. 
> 
> Is there no way to read everything a channel's got currently got without
> blocking?


Yes, there is a way - os.read() (also known as posix.read())

It's better not to mix buffered I/O (like file object
I/O functions) with select() at all, because select()
actually applies to system level file descriptors and
doesn't know anything about the buffer.

Get the file descriptor with fileno(), and never refer
to the file object again after that.

   Donn Cave, [EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: non blocking read()

2004-12-01 Thread David Bolen
Jp Calderone <[EMAIL PROTECTED]> writes:

> def nonBlockingReadAll(fileObj):
> bytes = []
> while True:
> b = fileObj.read(1024)
> bytes.append(b)
> if len(b) < 1024:
> break
> return ''.join(bytes)

Wouldn't this still block if the input just happened to end at a
multiple of the read size (1024)?

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


Re: recombination variations

2004-12-01 Thread Peter Otten
David Siedband wrote:

> The problem I'm solving is to take a sequence like 'ATSGS' and make all
> the DNA sequences it represents.  The A, T, and G are fine but the S
> represents C or G.  I want to take this input:
> 
> [ [ 'A' ] , [ 'T' ] , [ 'C' , 'G' ], [ 'G' ] , [ 'C' , 'G' ] ]
> 
> and make the list:
> 
> [ 'ATCGC' , 'ATCGG' , 'ATGGC' , 'ATGGG' ]

[...]

The code you provide only addresses the first part of your problem, and so
does mine:

>>> def disambiguate(seq, alphabet):
... return [list(alphabet.get(c, c)) for c in seq]
...
>>> alphabet = {
... "W": "AT",
... "S": "CG"
... }
>>> disambiguate("ATSGS", alphabet)
[['A'], ['T'], ['C', 'G'], ['G'], ['C', 'G']]

Note that "identity entries" (e. g. mapping "A" to "A") in the alphabet
dictionary are no longer necessary. The list() call in disambiguate() is
most likely superfluous, but I put it in to meet your spec accurately.

Now on to the next step :-)

Peter

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


Re: Python Win32 Silent Install

2004-12-01 Thread Trent Mick
Matt Gerrans wrote:
Maybe there is a better way to do an unattended install of the Win32 
extensions (that is, perhaps without using the binary)?
You could use the ActivePython MSI package, which includes the PyWin32 
extensions and offers a silent install option:

http://aspn.activestate.com/ASPN/docs/ActivePython/2.4/installnotes.html#install_silent
Cheers,
Trent
--
Trent Mick
[EMAIL PROTECTED]
--
http://mail.python.org/mailman/listinfo/python-list


Re: assymetry between a == b and a.__eq__(b) (WAS: pre-PEP genericobjects)

2004-12-01 Thread Terry Reedy

"Steven Bethard" <[EMAIL PROTECTED]> wrote in message
 >>>def __eq__(self, other):
>>>"""x.__eq__(y) <==> x == y"""
>>>return (isinstance(other, self.__class__)

Since an instance of a subclass is an instance of a parent class, but not 
vice versa, I believe you introduce here the assymetry you verify below.

>>>and self.__dict__ == other.__dict__)
>> This results in an asymmetry:
>>
>from bunch import Bunch
>class B(Bunch): pass
>> ...
>B().__eq__(Bunch())
>> False
>Bunch().__eq__(B())
>> True

Terry J. Reedy



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


Re: Python Win32 Silent Install

2004-12-01 Thread Matt Gerrans
That sounds easy enough, but I imagine the Acive State package requires some 
kind of licensing.I'm pre-installing on millions of consumer PCs. 


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


PIL for Python 2.4 ?

2004-12-01 Thread Michel Claveau - abstraction méta-galactique non triviale en fuite perpétuelle.
Hi !

I can't install PIL on Python 2.4 ; the soft search Python 2.3 ; gh
!
Do you know if the great F.L. want to make, soon, a P24 version ?

Thanks !
-- 
Michel Claveau



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


Re: assymetry between a == b and a.__eq__(b) (WAS: pre-PEP genericobjects)

2004-12-01 Thread Steven Bethard
Terry Reedy wrote:
"Steven Bethard" <[EMAIL PROTECTED]> wrote in message
 >>>def __eq__(self, other):
  """x.__eq__(y) <==> x == y"""
  return (isinstance(other, self.__class__)

Since an instance of a subclass is an instance of a parent class, but not 
vice versa, I believe you introduce here the assymetry you verify below.
Yes, the asymmetry is due to isinstance.
I believe what Peter Otten was pointing out is that calling __eq__ is 
not the same as using ==, presumably because the code for == checks the 
types of the two objects and returns False if they're different before 
the __eq__ code ever gets called.

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


Re: Python 2.4 Uninstall Entry in WinXP Registry

2004-12-01 Thread "Martin v. Löwis"
Brad Tilley wrote:
I found the documentation here:
http://python.fyxm.net/2.4/msi.html
The original, of course, is at
http://python.org/2.4/msi.html
Regards,
Martin
--
http://mail.python.org/mailman/listinfo/python-list


Re: Python 2.4 Uninstall Entry in WinXP Registry

2004-12-01 Thread Brad Tilley
Martin v. Löwis wrote:
Brad Tilley wrote:
I found the documentation here:
http://python.fyxm.net/2.4/msi.html

The original, of course, is at
http://python.org/2.4/msi.html
Regards,
Martin
Thanks Martin... going to a .msi was a great move... we can do fully 
automated, unattended installs now. I appreaciate your work.

P.S. Here's what my batch install file currently looks like:
msiexec /i python-2.4.msi /qb! ALLUSERS=1 ARPNOREMOVE=1 ARPNOMODIFY=1 
ARPNOREPAIR=1 ADDLOCAL=ALL TARGETDIR="C:\Program Files\Python24"

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


Re: PIL for Python 2.4 ?

2004-12-01 Thread Simon John
Michel Claveau - abstraction méta-galactique non triviale en fuite
perpétuelle. wrote:
> Hi !
>
> I can't install PIL on Python 2.4 ; the soft search Python 2.3 ;
gh
> !
> Do you know if the great F.L. want to make, soon, a P24 version ?

Yes, this kind of thing is stopping me trying 2.4 for a while, as I
need at least py2exe (has a 0.54beta 2.4 version), wxPython 2.5 and
cxFreeze3 for 2.4, and PyQt, Tkinter etc. would be nice too ;-)

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


Re: Regular Expression Problem...

2004-12-01 Thread Caleb Hattingh
Obviously, Peter and Jorge are hardcore, but below is what a beginner like  
me hacked up:

My point, I guess, is that it is possible to quickly get a solution to a  
specific problem like this without being a total expert.  The code below  
was typed out once, and with only one minor correction before it produced  
the required behaviour.  Sure, it is not the general solution, but *this  
is WHY I use python* - You get a lot of mileage out of the basics.  Plus,  
I can still read and understand the sub-optimal code, and probably will be  
able to several years from now :)

Regular expressions are real powerful, and I am learning through using ViM  
- but it takes time and practice.

(err, I didn't include your example with quotes, but you should get the  
general idea)
***
'>>> stngs = [r'This Is An $EXAMPLE String', r'This Is An  
$EXAMPLE.String', r'This Is An $EXAMPLE',r'This Is An \$EXAMPLE\String']
'>>> stngs
['This Is An $EXAMPLE String', 'This Is An $EXAMPLE.String', 'This Is An  
$EXAMPLE', 'This Is An \\$EXAMPLE\\String']

'>>> for i in stngs:
wdlist = i.split(' ')
for j in wdlist:
if j.find(r'$') > -1:
dwd = j.split('.')[0]
if dwd.find('\\') > -1:
dwd = dwd.split('\\')[1]
print dwd

$EXAMPLE
$EXAMPLE
$EXAMPLE
$EXAMPLE
'>>>
***

On Wed, 01 Dec 2004 13:40:17 +0100, Peter Otten <[EMAIL PROTECTED]> wrote:
[EMAIL PROTECTED] wrote:
identifying/extracting a substring from another string. What I have to  
do
is to extract all the strings that begins with a "$" character, but
excluding characters like "." (point) and "'" (single quote) and "\" "/"
(slashes). For example I have:

1) This Is An $EXAMPLE String
2) This Is An $EXAMPLE.String
3) 'This Is An $EXAMPLE'
4) This Is An \$EXAMPLE\String;
I would like to extract only the "keyword" $EXAMPLE and what I'm using  
at
Is that what you want?
import re
r = re.compile("[$]\w+")
r.findall("""
... 1) This Is An $EXAMPLE String
... 2) This Is An $EXAMPLE.String
... 3) 'This Is An $EXAMPLE'
... 4) This Is An \$EXAMPLE\String;
... """)
['$EXAMPLE', '$EXAMPLE', '$EXAMPLE', '$EXAMPLE']
Peter
--
http://mail.python.org/mailman/listinfo/python-list


Time zones

2004-12-01 Thread Timothy Hume
Hi,

I want to ensure that all my time calculations are done in UTC. This is 
easy with Python on UNIX machines. I simply set the TZ environment 
variable to "UTC", and it ensures that the time functions use UTC. 

My question is, how do I get similar functionality using Python on 
Windows?

Thanks,

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


Re: non blocking read()

2004-12-01 Thread Jp Calderone
On 01 Dec 2004 15:55:18 -0500, David Bolen <[EMAIL PROTECTED]> wrote:
>Jp Calderone <[EMAIL PROTECTED]> writes:
> 
> > def nonBlockingReadAll(fileObj):
> > bytes = []
> > while True:
> > b = fileObj.read(1024)
> > bytes.append(b)
> > if len(b) < 1024:
> > break
> > return ''.join(bytes)
> 
> Wouldn't this still block if the input just happened to end at a
> multiple of the read size (1024)?

  Only if the file has not been put into non-blocking mode.  But the function 
as given is wrong, I left out the exception handling in the case you mention.  
Rather than blocking forever, fileObj.read(1024) will raise IOError (EAGAIN) if 
the input happened to be a multiple of 1024 bytes long.  Here is the corrected 
version:

def nonBlockingReadAll(fileObj):
bytes = []
while True:
try:
b = fileObj.read(1024)
except IOError, e:
if e.args[0] == errno.EAGAIN:
break
raise
bytes.append(b)
if len(b) < 1024:
break
return ''.join(bytes)

  Arguably, there is no longer any point to checking the length of b in this 
version, since at worst you will break on the next iteration of the loop.  It 
doesn't hurt, though.

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


Re: Python 3000 and "Python Regrets"

2004-12-01 Thread Gustavo Córdova Avila
Brad Tilley wrote:
Matt Gerrans wrote:
Anyway, what's to worry about?When the time comes just whip out a 
little script that converts Python 1.6 (or whatever you like) to 
Python3K; it will only take seven lines of P3K code.
How about 'import classic'
from past import python23
:-)
--
Gustavo Córdova Avila <[EMAIL PROTECTED]> 

*Tel:* +52 (81) 8130-1919 ext. 127
Integraciones del Norte, S.A. de C.V.
Padua #6047, Colonia Satélite Acueducto
Monterrey, Nuevo León, México.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Identifying exceptions that can be raised

2004-12-01 Thread Andrew Dalke
Tim Jarman wrote:
OK, I'm an arts graduate[1] so this is probably a really stupid 
question, but what kind(s) of science would be non-experimental?
Astronomy.  Archaeology.  Paleontology.  Seismology.  Cosmic ray
research.
There have been a few experiments in environmental science, like
tenting a small island off the coast of Florida to kill all the
insects then watch how they are reintroduced.
Geology, unless you count the material science work used to
understand how minerals change under pressure and heat, or
including mining as part of geology.
Andrew
[EMAIL PROTECTED]
--
http://mail.python.org/mailman/listinfo/python-list


Re: non blocking read()

2004-12-01 Thread Gustavo Córdova Avila
David Bolen wrote:
Jp Calderone <[EMAIL PROTECTED]> writes:
   def nonBlockingReadAll(fileObj):
   bytes = []
   while True:
   b = fileObj.read(1024)
   bytes.append(b)
   if len(b) < 1024:
   break
   return ''.join(bytes)
Wouldn't this still block if the input just happened to end at a
multiple of the read size (1024)?
-- David
No, it'll read up to 1024 bytes or as much as it can, and
then return an apropriatly sized string.
--
Gustavo CÃrdova Avila <[EMAIL PROTECTED]> 

*Tel:* +52 (81) 8130-1919 ext. 127
Integraciones del Norte, S.A. de C.V.
Padua #6047, Colonia SatÃlite Acueducto
Monterrey, Nuevo LeÃn, MÃxico.


signature.asc
Description: OpenPGP digital signature
-- 
http://mail.python.org/mailman/listinfo/python-list

Python 2.4 and Tkinter

2004-12-01 Thread Jeffrey Barish
Since upgrading to python 2.4 yesterday, I am no longer able to use
Tkinter.  From http://www.python.org/moin/TkInter I learned that I need
to edit Modules/Setup to include Tkinter during the make.  However, it
isn't clear to me what modifications to make.  I am supposed to specify
directories in which needed files can be found.  I found the Tcl/Tk
libraries in /usr/local/lib/python2.4/lib-tk, but I can't find the
Tcl/Tk headers.  The default value for the headers (/usr/local/include)
doesn't work.  I searched my system for tcl.h but couldn't find it. 
Does anyone know how to make Tkinter work under Python 2.4?

I also don't understand why I have to go to all this trouble.  Tkinter
is supposed to be included with Python, so shouldn't it be available
without any special effort?
-- 
Jeffrey Barish

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


Re: Python Win32 Silent Install

2004-12-01 Thread Steve Holden
Matt Gerrans wrote:
That sounds easy enough, but I imagine the Acive State package requires some 
kind of licensing.I'm pre-installing on millions of consumer PCs. 


Ah, so your group is responsible for all the "I've found Python on my 
computer, what does it do and can I remove it" messages we saw last year?

You are right about ActiveState, the copy you download from their web 
site is licensed to prohibit redistribution. They might be prepared to 
cut you a special license, but you'd have to ask them about that.

I'm guessing Mark Hammond would be able to build you a silent installer 
for a modest price.

Off-topic, I'd be very interested to learn anything you could tell us 
about why HP are installing Python (what it's used for, what you 
experience has been, &c). If this could be made public it would be nice 
to include it as a "Python success story".

regards
 Steve
(PSF PR Committee Chair)
--
http://www.holdenweb.com
http://pydish.holdenweb.com
Holden Web LLC +1 800 494 3119
--
http://mail.python.org/mailman/listinfo/python-list


String operations

2004-12-01 Thread Anoop Rajendra
Hi. I'm trying to resolve an issue with strings.

The command(inclusive of the back-slashes)

condor_q -l -constraint "ProjectId==\"anoopr_samadams.fnal.gov_161903_30209\""

is the only way the command returns the right result. 
I'm trying to run this command from inside a python program.
The way I can get it work is by: 

os.system('condor_q -l -constraint 
"ProjectId==\\\"anoopr_samadams.fnal.gov_161903_30209\\\""')

But, I'd rather use the os.exec functions to get the output. But 

os.execvp("condor_q",["condor_q","-l","-constraint",'"ProjectId==\\\"anoopr_samadams.fnal.gov_161903_30209\\\""'])

doesnt work. Its definately a problem with one of the million
backslashes and quotes present, but I'm not able to figure it out.
What am I doing wrong?

Thanks,
Anoop ///

The happiest time of a person's life is after his first divorce.
  -- J.K. Galbraith 


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


wxPython to build an HTML analyser/displayer?

2004-12-01 Thread Luke Skywalker
Hi,

Currently, I use filters in Privoxy followed by a JavaScript embedded
script to further filter a web page that is restricted to IE (because
of incompatibilities of the DOM), and was wondering if it'd be
feasible to write a Python GUI app with wxPython that would do the
same, ie. fetch a web page, analyse its contents and filter/rewrite,
before displaying it in a HTML renderer? Does wxWidgets offer an HTML
displayer widget, and is it good enough?

Thank you
Luke.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: non blocking read()

2004-12-01 Thread Donn Cave
In article <[EMAIL PROTECTED]>,
 Gustavo Córdova Avila <[EMAIL PROTECTED]> wrote:

> David Bolen wrote:
> 
> >Jp Calderone <[EMAIL PROTECTED]> writes:
> >
> >>def nonBlockingReadAll(fileObj):
> >>bytes = []
> >>while True:
> >>b = fileObj.read(1024)
> >>bytes.append(b)
> >>if len(b) < 1024:
> >>break
> >>return ''.join(bytes)
> >>
> >Wouldn't this still block if the input just happened to end at a
> >multiple of the read size (1024)?
> >
> >-- David
> >
> No, it'll read up to 1024 bytes or as much as it can, and
> then return an apropriatly sized string.

Depends.  I don't believe the original post mentioned
that the file is a pipe, socket or similar, but it's
kind of implied by the use of select() also mentioned.
It's also kind of implied by use of the term "block" -
disk files don't block.

If we are indeed talking about a pipe or something that
really can block, and you call fileobject.read(1024),
it will block until it gets 1024 bytes.

   Donn Cave, [EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: String operations

2004-12-01 Thread Steve Holden
Anoop Rajendra wrote:
Hi. I'm trying to resolve an issue with strings.
The command(inclusive of the back-slashes)
condor_q -l -constraint "ProjectId==\"anoopr_samadams.fnal.gov_161903_30209\""
is the only way the command returns the right result. 
I'm trying to run this command from inside a python program.
The way I can get it work is by: 

os.system('condor_q -l -constraint 
"ProjectId==\\\"anoopr_samadams.fnal.gov_161903_30209\\\""')
But, I'd rather use the os.exec functions to get the output. But 

os.execvp("condor_q",["condor_q","-l","-constraint",'"ProjectId==\\\"anoopr_samadams.fnal.gov_161903_30209\\\""'])
doesnt work. Its definately a problem with one of the million
backslashes and quotes present, but I'm not able to figure it out.
What am I doing wrong?
I believe that you don't need to escape the quotes inside the argument 
strings when you call os.execvp(), because there's no shell interpreting 
the arguments. So, in theory, what you appear to need would be

os.execvp("condor_q",["condor_q","-l","-constraint",'ProjectId=="anoopr_samadams.fnal.gov_161903_30209"'])
or even, since I don't see the need for the quotes in the first place,
os.execvp("condor_q",["condor_q","-l","-constraint",'ProjectId==anoopr_samadams.fnal.gov_161903_30209'])
or
os.execvp("condor_q",["condor_q","-l","-constraint","ProjectId==anoopr_samadams.fnal.gov_161903_30209"])
regards
 Steve
--
http://www.holdenweb.com
http://pydish.holdenweb.com
Holden Web LLC +1 800 494 3119
--
http://mail.python.org/mailman/listinfo/python-list


Re: Python Win32 Silent Install

2004-12-01 Thread Luke Skywalker
On Wed, 01 Dec 2004 17:15:38 -0500, Steve Holden <[EMAIL PROTECTED]>
wrote:

>You are right about ActiveState, the copy you download from their web 
>site is licensed to prohibit redistribution. They might be prepared to 
>cut you a special license, but you'd have to ask them about that.

Does it mean it's not allowed to build an application with ActiveState
Python, and generate an installer that installs the whole thing,
forcing users to go to ActiveState's web site and download the
interpreter? Gee, that changes everything...

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


Re: Time zones

2004-12-01 Thread David Bolen
Timothy Hume <[EMAIL PROTECTED]> writes:

> I want to ensure that all my time calculations are done in UTC. This is 
> easy with Python on UNIX machines. I simply set the TZ environment 
> variable to "UTC", and it ensures that the time functions use UTC. 
> 
> My question is, how do I get similar functionality using Python on 
> Windows?

If you're just talking about time module functions, I think you should
be able to do the same thing.  The time functions are overlays for the
C library versions which do use tzset() and look at the TZ environment
variable as under Unix.

> py24
Python 2.4 (#60, Nov 30 2004, 11:49:19) [MSC v.1310 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import time
>>> print time.tzname
('Eastern Standard Time', 'Eastern Daylight Time')
>>> print time.ctime()
Wed Dec 01 17:42:08 2004

> TZ=UTC py24
Python 2.4 (#60, Nov 30 2004, 11:49:19) [MSC v.1310 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import time
>>> print time.tzname
('UTC', '')
>>> print time.ctime()
Wed Dec 01 22:42:21 2004


(I've used 2.4 here, but the same results work back until 1.5.2)

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


Re: Python Win32 Silent Install

2004-12-01 Thread Steve Holden
Luke Skywalker wrote:
On Wed, 01 Dec 2004 17:15:38 -0500, Steve Holden <[EMAIL PROTECTED]>
wrote:

You are right about ActiveState, the copy you download from their web 
site is licensed to prohibit redistribution. They might be prepared to 
cut you a special license, but you'd have to ask them about that.

Does it mean it's not allowed to build an application with ActiveState
Python, and generate an installer that installs the whole thing,
forcing users to go to ActiveState's web site and download the
interpreter? Gee, that changes everything...
Luke.
Obviously the license agreement at 
http://www.activestate.com/Products/ActivePython/license_agreement.plex 
would be the authoritative statement. ActiveState do, however, license 
their distribution for OEM purposes, as the links to the right of the 
above-quoted page suggest.

However, the current Community License (v4) says: """ ...
   2. You may make and give away verbatim copies of this Package for 
personal use, or for use within your organization, provided that you 
duplicate all of the original copyright notices and associated 
disclaimers. You may not distribute copies of this Package, or copies of 
packages derived from this Package, to others outside your organization 
without specific prior written permission from ActiveState (although you 
are encouraged to direct them to sources from which they may obtain it 
for themselves). ..."""

This makes is pretty clear that if you plan to distribute outside your 
own organization they expect you to get an OEM license if you want to 
use their distribution.

regards
 Steve
--
http://www.holdenweb.com
http://pydish.holdenweb.com
Holden Web LLC +1 800 494 3119
--
http://mail.python.org/mailman/listinfo/python-list


Re: non blocking read()

2004-12-01 Thread Steve Holden
Donn Cave wrote:
In article <[EMAIL PROTECTED]>,
 Gustavo Córdova Avila <[EMAIL PROTECTED]> wrote:

David Bolen wrote:

Jp Calderone <[EMAIL PROTECTED]> writes:

  def nonBlockingReadAll(fileObj):
  bytes = []
  while True:
  b = fileObj.read(1024)
  bytes.append(b)
  if len(b) < 1024:
  break
  return ''.join(bytes)
Wouldn't this still block if the input just happened to end at a
multiple of the read size (1024)?
-- David
No, it'll read up to 1024 bytes or as much as it can, and
then return an apropriatly sized string.

Depends.  I don't believe the original post mentioned
that the file is a pipe, socket or similar, but it's
It did actually specifically mention files.
kind of implied by the use of select() also mentioned.
It's also kind of implied by use of the term "block" -
disk files don't block.
Erm, you mean they operate at infinite speed? Wrong. There's a definite 
risk that a process will block when reading from disk, and the reason 
that (Unix) files can be the object of select() calls is to allow users 
to perform non-blocking reads and continue to process while waiting for 
disk data to arrive.

I agree the blocking period is *more predictable* than for network data, 
but "disk file access won't cause a process to block" is a misleading 
and incorrect, though frequent, assumption.

I agree that it's difficult to actually write asynchronous disk I/O in 
such a way as to improve performance, but it can be done. Except on 
platforms where select() can't be applied to disk files, of course. In 
practice most applications that need the scalability will use threading 
or multiple processes.

If we are indeed talking about a pipe or something that
really can block, and you call fileobject.read(1024),
it will block until it gets 1024 bytes.
   Donn Cave, [EMAIL PROTECTED]
Disk access can block. When access is made to a file object in 
non-blocking mode it will return whatever data there are immediately 
available in the buffers, up to the number of bytes requested. If the 
buffers are currently empty the process will generate an error (which in 
Python becomes an exception).

regards
 Steve
--
http://www.holdenweb.com
http://pydish.holdenweb.com
Holden Web LLC +1 800 494 3119
--
http://mail.python.org/mailman/listinfo/python-list


  1   2   >