Re: question of style

2009-07-02 Thread Tim Harig
On 2009-07-02, Paul Rubin wrote: > Tim Harig writes: >> If lower is 5 and higher is 3, then it returns 3 because 3 != None in the >> first if. > Sorry, the presumption was that lower <= higher, i.e. the comparison > had already been made and the invariant was enforced by the class > constructor.

Re: XML(JSON?)-over-HTTP: How to define API?

2009-07-02 Thread Chris Rebert
On Thu, Jul 2, 2009 at 3:06 PM, Allen Fowler wrote: > > I have an (in-development) python system that needs to shuttle events / > requests around over the network to other parts of itself.   It will also > need to cooperate with a .net application running on yet a different machine. > > So, natur

Re: how to spawn a process under different user

2009-07-02 Thread Tim Harig
On 2009-07-02, sanket wrote: >> sanket wrote: >> > I am trying to use python's subprocess module to launch a process. >> > but in order to do that I have to change the user. > I am using python 2.4 on centos. I have never done this in python; but, using the normal system calls in C the process is

Re: XML(JSON?)-over-HTTP: How to define API?

2009-07-02 Thread Paul Rubin
Allen Fowler writes: > Since I need to work with other platforms, pickle is out... what > are the alternatives? XML? JSON? json is the easiest to prototype with and is less bureaucratic. xml has more serious tools for schema specification and validation etc. You could start with json and switc

Re: XML(JSON?)-over-HTTP: How to define API?

2009-07-02 Thread Charles Yeomans
On Jul 2, 2009, at 6:06 PM, Allen Fowler wrote: I have an (in-development) python system that needs to shuttle events / requests around over the network to other parts of itself. It will also need to cooperate with a .net application running on yet a different machine. So, naturally

Detecting platform architecture with Parallels and Win XP x64

2009-07-02 Thread Doug McCorkle
Hello, I am using Python 2.5.4 on Windows XP x64 with Parallels. When I try to use: distutils.util.get_platform sys.platform I always get win32 but if I use: platform.architecture() with the amd64 installer I get 64bit for the first argument. Is there a way to detect win64 without having

Re: question of style

2009-07-02 Thread Paul Rubin
Tim Harig writes: > That being the case, it might be a good idea either to handle the situation > and raise an exception or add: > > assert self.lower <= self.higher > > That way an exception will be raised if there is an error somewhere else > in the code rather then silently passing a possibly

Re: regex question on .findall and \b

2009-07-02 Thread Ethan Furman
Ethan Furman wrote: Greetings! My closest to successfull attempt: Python 2.5.4 (r254:67916, Dec 23 2008, 15:10:54) [MSC v.1310 32 bit (Intel)] Type "copyright", "credits" or "license" for more information. IPython 0.9.1 -- An enhanced Interactive Python. In [161]: re.findall('\d+','this i

Re: String to List Question

2009-07-02 Thread Rhodri James
On Thu, 02 Jul 2009 23:05:46 +0100, Hanna Michelsen wrote: Hi, I am brand new to python and I love it, but I've been having some trouble with a file parser that I've been working on. It contains lines that start with a name and then continue with names, nicknames and phone numbers of peop

Is Psyco good for Python 2.6.1?

2009-07-02 Thread Russ P.
I need to speed up some Python code, and I discovered Psyco. However, the Psyco web page has not been updated since December 2007. Before I go to the trouble of installing it, does anyone know if it is still good for Python 2.6.1? Thanks. -- http://mail.python.org/mailman/listinfo/python-list

Re: question of style

2009-07-02 Thread Tim Harig
On 2009-07-02, Paul Rubin wrote: > Tim Harig writes: >> That being the case, it might be a good idea either to handle the situation >> and raise an exception or add: >> assert self.lower <= self.higher >> That way an exception will be raised if there is an error somewhere else >> in the code rath

Re: question of style

2009-07-02 Thread Tim Harig
On 2009-07-02, Tim Harig wrote: > Sorry, it worked under 2.5: [SNIP] > None seems to have been evaluated less then any integer. The same isn't > true under 3.0: None seem to have been evaluated less then any non-negative integer including 0. -- http://mail.python.org/mailman/listinfo/python-lis

Re: question of style

2009-07-02 Thread Simon Forman
On Jul 2, 4:08 pm, Erik Max Francis wrote: > Simon Forman wrote: > > Hey I was hoping to get your opinions on a sort of minor stylistic > > point. > > These two snippets of code are functionally identical. Which would you > > use and why? > > The first one is easier [for me anyway] to read and und

Python 3.0 (pinin' for the fjords)

2009-07-02 Thread Barry Warsaw
Now that Python 3.1 is out, it seems there's been some confusion as to whether there will be one last Python 3.0 release, i.e. Python 3.0.2. At the PyCon 2009 language summit it was decided that there will be *no* Python 3.0.2. Python 3.0 is different than all other releases. There will b

Re: question of style

2009-07-02 Thread Simon Forman
On Jul 2, 3:57 pm, Scott David Daniels wrote: > Duncan Booth wrote: > > Simon Forman wrote: > >> ... > >> if self.higher is self.lower is None: return > >> ... > > As a matter of style however I wouldn't use the shorthand to run two 'is' > > comparisons together, I'd write that out in full if it

Re: Is Psyco good for Python 2.6.1?

2009-07-02 Thread Mensanator
On Jul 2, 5:41 pm, "Russ P." wrote: > I need to speed up some Python code, and I discovered Psyco. However, > the Psyco web page has not been updated since December 2007. Before I > go to the trouble of installing it, does anyone know if it is still > good for Python 2.6.1? Thanks. Go back to the

Re: question of style

2009-07-02 Thread Paul Rubin
Tim Harig writes: > > Well, that assert is not right because you have to handle the case > > where one of the values is None... > Sorry, it worked under 2.5: Well, it didn't crash under 2.5. Whether the result was correct is a different question. > None seems to have been evaluated less the

Re: Searching equivalent to C++ RAII or deterministic destructors

2009-07-02 Thread ryles
> You can go ahead and implement a __del__() method. It will often work in > CPython, but you get no guarantees, especially when you have reference > cycles and with other Python implementations that don't use refcounting. And for resources whose lifetime is greater than your process (e.g. a file)

Re: how to spawn a process under different user

2009-07-02 Thread Gabriel Genellina
En Thu, 02 Jul 2009 19:27:05 -0300, Tim Harig escribió: On 2009-07-02, sanket wrote: sanket wrote: > I am trying to use python's subprocess module to launch a process. > but in order to do that I have to change the user. I am using python 2.4 on centos. I have never done this in python;

Re: stringio+tarfile

2009-07-02 Thread Gabriel Genellina
En Thu, 02 Jul 2009 17:57:49 -0300, superpollo escribió: why the following does not work? can you help me correct (if possible)? Explain "does not work" please. Does it raise an exception? Which one? Please post the complete traceback. You don't get the expected result? Tell us what did you e

Re: question of style

2009-07-02 Thread Paul Rubin
Simon Forman writes: > This code is part of a delete() method for a binary tree > implementation. "None" is used to simulate a NULL pointer. In the case > where both children are non-None the code goes on to handle that. > > None is a "unitary" or "singleton" value, so "is" is the right > compari

Re: dealloc function in python extend c module

2009-07-02 Thread Gabriel Genellina
En Thu, 02 Jul 2009 14:22:53 -0300, Philip Semanchuk escribió: On Jul 2, 2009, at 2:11 AM, Shen, Yu-Teh wrote: I create my extend type something like http://www.python.org/doc/current/extending/newtypes.html. And my type has a member which is a pointer point to my allocate memory ( no ref co

Re: A question about fill_free_list(void) function

2009-07-02 Thread Gabriel Genellina
En Thu, 02 Jul 2009 07:55:42 -0300, Pedram escribió: On Jul 2, 1:11 pm, Peter Otten <__pete...@web.de> wrote: [snip explanation of strange pointer manipulations in the C code of the integer type] Oh, I got it! What a wonderful implementation! :o Well, I would not say it's "wonderful"...

Re: Multi thread reading a file

2009-07-02 Thread ryles
On Jul 2, 6:10 am, "Gabriel Genellina" wrote: > En Wed, 01 Jul 2009 12:49:31 -0300, Scott David Daniels   > escribió: > > These loops work well with the two-argument version of iter, > > which is easy to forget, but quite useful to have in your bag > > of tricks: > > >      def convert(in_queue,

Re: Multi thread reading a file

2009-07-02 Thread Paul Rubin
ryles writes: > >>> # Oh... yeah. I really *did* want 'is None' and not '== None' > >>> which iter() will do. Sorry guys! > > Please don't let this happen to you too ;) None is a perfectly good value to put onto a queue. I prefer using a unique sentinel to mark the end of the stream: sentin

Re: What are the limitations of cStringIO.StringIO() ?

2009-07-02 Thread ryles
This reminds me. Would anyone object to adding a sentence to http://docs.python.org/library/stringio.html#module-cStringIO just to mention that attributes cannot be added to a cStringIO, like such: % import cStringIO, StringIO % StringIO.StringIO().value = 1 % cStringIO.StringIO().value = 1 Traceb

Re: Is Psyco good for Python 2.6.1?

2009-07-02 Thread Bearophile
Russ P.: Python works well to me on Python 2.6+, on Windows. You can find a compiled version too, around. Bye, bearophile -- http://mail.python.org/mailman/listinfo/python-list

Re: stringio+tarfile

2009-07-02 Thread Dave Angel
superpollo wrote: why the following does not work? can you help me correct (if possible)? 1 import tarfile 2 import StringIO 3 sf1 = StringIO.StringIO("one\n") 4 sf2 = StringIO.StringIO("two\n") 5 tf = StringIO.StringIO() 6 tar = tarfile.open(tf , "w")

Re: What are the limitations of cStringIO.StringIO() ?

2009-07-02 Thread Simon Forman
On Wed, Jul 1, 2009 at 7:48 AM, Barak, Ron wrote: > Hi, > > I think I'm up against a limitation in cStringIO.StringIO(), but could not > find any clues on the web, especially not in > http://docs.python.org/library/stringio.html. > > What I have is the following function: > >     def concatenate_fi

Re: What are the limitations of cStringIO.StringIO() ?

2009-07-02 Thread Benjamin Peterson
ryles gmail.com> writes: > > This reminds me. Would anyone object to adding a sentence to > http://docs.python.org/library/stringio.html#module-cStringIO just to > mention that attributes cannot be added to a cStringIO, like such: That's true of almost all types that are implemented in C. -

Re: Adding an object to the global namespace through " f_globals" is that allowed ?

2009-07-02 Thread ryles
On Jul 2, 1:25 am, Terry Reedy wrote: > > The next statement works, > > but I'm not sure if it will have any dramatical side effects, > > other than overruling a possible object with the name A > > > def some_function ( ...) : > > A = object ( ...) > > sys._getframe(1).f_globals [ Name ]

Sequence splitting

2009-07-02 Thread schickb
I have fairly often found the need to split a sequence into two groups based on a function result. Much like the existing filter function, but returning a tuple of true, false sequences. In Python, something like: def split(seq, func=None): if func is None: func = bool t, f = [], [

Re: Python 3.0 (pinin' for the fjords)

2009-07-02 Thread Alan G Isaac
Using the 3.1 Windows installer, I chose that I did not want the extensions registered, and the installer unregistered the .py and .pyw extensions (which I had wanted to keep associated with Python 2.6). Is this intentional? Alan Isaac PS I already fixed the problem. My question is about intent

Re: Multi thread reading a file

2009-07-02 Thread ryles
On Jul 2, 10:20 pm, Paul Rubin wrote: > ryles writes: > > >>> # Oh... yeah. I really *did* want 'is None' and not '== None' > > >>> which iter() will do. Sorry guys! > > > Please don't let this happen to you too ;) > > None is a perfectly good value to put onto a que

Re: Sequence splitting

2009-07-02 Thread Paul Rubin
schickb writes: > def split(seq, func=None): > if func is None: > func = bool > t, f = [], [] > for item in seq: > if func(item): > t.append(item) > else: > f.append(item) > return (t, f) untested: def split(seq, func=bool):

Re: dealloc function in python extend c module

2009-07-02 Thread Philip Semanchuk
On Jul 2, 2009, at 9:28 PM, Gabriel Genellina wrote: En Thu, 02 Jul 2009 14:22:53 -0300, Philip Semanchuk escribió: Hi Shen, I'm no expert on Python memory management, but since no once else has answered your question I'll tell you what I *think* is happening. Python doesn't delete objec

Re: Sequence splitting

2009-07-02 Thread Pablo Torres N.
On Thu, Jul 2, 2009 at 21:56, schickb wrote: > I have fairly often found the need to split a sequence into two groups > based on a function result. Much like the existing filter function, > but returning a tuple of true, false sequences. In Python, something > like: > > def split(seq, func=None): >

Re: Multi thread reading a file

2009-07-02 Thread Paul Rubin
ryles writes: > >    sentinel = object() > > I agree, this is cleaner than None. We're still in the same boat, > though, regarding iter(). Either it's 'item == None' or 'item == object ()' Use "item is sentinel". -- http://mail.python.org/mailman/listinfo/python-list

Re: Sequence splitting

2009-07-02 Thread Pablo Torres N.
On Jul 2, 9:56 pm, schickb wrote: > I have fairly often found the need to split a sequence into two groups > based on a function result. Much like the existing filter function, > but returning a tuple of true, false sequences. In Python, something > like: > > def split(seq, func=None): >     if fu

Re: Multi thread reading a file

2009-07-02 Thread Gabriel Genellina
En Fri, 03 Jul 2009 00:15:40 -0300, > escribió: ryles writes: >    sentinel = object() I agree, this is cleaner than None. We're still in the same boat, though, regarding iter(). Either it's 'item == None' or 'item == object ()' Use "item is sentinel". We're talking about the iter() bui

Re: question of style

2009-07-02 Thread Simon Forman
On Jul 2, 9:30 pm, Paul Rubin wrote: > Simon Forman writes: > > This code is part of a delete() method for a binary tree > > implementation. "None" is used to simulate a NULL pointer. In the case > > where both children are non-None the code goes on to handle that. >

Re: Sequence splitting

2009-07-02 Thread Brad
On Jul 2, 8:14 pm, Paul Rubin wrote: > schickb writes: > > def split(seq, func=None): > >     if func is None: > >         func = bool > >     t, f = [], [] > >     for item in seq: > >         if func(item): > >             t.append(item) > >         else: > >      

Re: Multi thread reading a file

2009-07-02 Thread Paul Rubin
"Gabriel Genellina" writes: > We're talking about the iter() builtin behavior, and that uses == > internally. Oh, I see. Drat. > It could have used an identity test, and that would be better for this > specific case. But then iter(somefile.read, '') wouldn't work. Yeah, it should allow supplyi

Re: Sequence splitting

2009-07-02 Thread Brad
On Jul 2, 8:17 pm, "Pablo Torres N." wrote: > On Jul 2, 9:56 pm, schickb wrote: > > > I have fairly often found the need to split a sequence into two groups > > based on a function result. > > This sounds like it belongs to the python-ideas list.  I suggest > posting there for better feedback, si

Re: multiprocessing: pool with blocking queue

2009-07-02 Thread ryles
On Jul 2, 11:09 am, masher wrote: > My questions, then, is: Is there a more elegant/pythonic way of doing > what I am trying to do with the current Pool class? Another thing you might try is to subclass Pool and add an apply_async () wrapper which would wait for _taskqueue.qsize() to reach the de

Re: Sequence splitting

2009-07-02 Thread Paul Rubin
Brad writes: > On Jul 2, 8:14 pm, Paul Rubin wrote: > > schickb writes: > > > def split(seq, func=None): > > >     if func is None: > > >         func = bool > > >     t, f = [], [] > > >     for item in seq: > > >         if func(item): > > >             t.append(

Re: Multi thread reading a file

2009-07-02 Thread ryles
On Jul 2, 11:55 pm, Paul Rubin wrote: > Yeah, it should allow supplying a predicate instead of using == on > a value.  How about (untested): > >    from itertools import * >    ... >    for row in takewhile(lambda x: x is sentinel, >                          starmap(i

Re: Sequence splitting

2009-07-02 Thread Brad
On Jul 2, 9:08 pm, Paul Rubin wrote: > Brad writes: > > On Jul 2, 8:14 pm, Paul Rubin wrote: > > > schickb writes: > > > > def split(seq, func=None): > > > >     if func is None: > > > >         func = bool > > > >     t, f = [], [] >

Re: Config files with different types

2009-07-02 Thread Lawrence D'Oliveiro
In message , Zach Hobesh wrote: > I want to be able to look at the value and determine what type it > SHOULD be. Right now, configs['overwrite'] = 'true' (a string) when > it might be more useful as a boolean. Typically the type should be what you expect, not what is given. For example, it doe

Re: Sequence splitting

2009-07-02 Thread Pablo Torres N.
On Thu, Jul 2, 2009 at 23:34, Brad wrote: > On Jul 2, 9:08 pm, Paul Rubin wrote: >> Brad writes: >> > On Jul 2, 8:14 pm, Paul Rubin wrote: >> > > schickb writes: >> > > > def split(seq, func=None): >> > > >     if func is None: >> > >

Re: getting rid of —

2009-07-02 Thread Simon Forman
On Jul 2, 4:31 am, Tep wrote: > On 2 Jul., 10:25, Tep wrote: > > > > > On 2 Jul., 01:56, MRAB wrote: > > > > someone wrote: > > > > Hello, > > > > > how can I replace '—' sign from string? Or do split at that character? > > > > Getting unicode error if I try to do it: > > > > > UnicodeDecodeErro

Re: question of style

2009-07-02 Thread Paul Rubin
Simon Forman writes: > > Yes, but the concept of null pointers is considered kludgy these days. > Seriously? "kludgy"? (I really AM getting old.) http://math.andrej.com/2009/04/11/on-programming-language-design/ discusses the issue (scroll down to "Undefined values" section). > Well I wouldn

Re: Sequence splitting

2009-07-02 Thread Paul Rubin
"Pablo Torres N." writes: > def split(seq, func=bool): > t = filter(func, seq) > f = filter(lambda x: not func(x), seq) > return list(t), list(f) That is icky--you're calling func (which might be slow) twice instead of once on every element of the seq. -- http://mail.python.org

Re: question of style

2009-07-02 Thread Lie Ryan
Tim Harig wrote: >> Speaking only to the style issue, when I've wanted to do something like >> that, I find: >>if self.higher is None is self.lower: >> more readable, by making clear they are both being compared to a >> constant, rather than compared to each other. > > By comparing them to

Re: question of style

2009-07-02 Thread Lie Ryan
Simon Forman wrote: > On Jul 2, 3:57 pm, Scott David Daniels wrote: >> Duncan Booth wrote: >>> Simon Forman wrote: ... if self.higher is self.lower is None: return ... >>> As a matter of style however I wouldn't use the shorthand to run two 'is' >>> comparisons together, I'd write

Re: Sequence splitting

2009-07-02 Thread Gabriel Genellina
En Fri, 03 Jul 2009 01:58:22 -0300, > escribió: "Pablo Torres N." writes: def split(seq, func=bool): t = filter(func, seq) f = filter(lambda x: not func(x), seq) return list(t), list(f) That is icky--you're calling func (which might be slow) twice instead of once on e

Re: Sequence splitting

2009-07-02 Thread Brad
On Jul 2, 9:40 pm, "Pablo Torres N." wrote: > > If it is speed that we are after, it's my understanding that map and > filter are faster than iterating with the for statement (and also > faster than list comprehensions).  So here is a rewrite: > > def split(seq, func=bool): >         t = filter(fu

Re: question of style

2009-07-02 Thread Lie Ryan
Paul Rubin wrote: > Generally, having a special > value like None to denote a missing datum was considered standard > practice a few decades ago, I guess in python, None as the missing datum idiom is still quite prevalent: def cat_list(a=None, b=None): # poor man's list concatenation if

Re: Sequence splitting

2009-07-02 Thread Brad
On Jul 2, 8:17 pm, "Pablo Torres N." wrote: > > This sounds like it belongs to the python-ideas list.  I suggest > posting there for better feedback, since the core developers check > that list more often than this one. I tried posting on python-ideas and received a "You are not allowed to post t

Re: question of style

2009-07-02 Thread Lie Ryan
Lie Ryan wrote: > Tim Harig wrote: >>> Speaking only to the style issue, when I've wanted to do something like >>> that, I find: >>>if self.higher is None is self.lower: >>> more readable, by making clear they are both being compared to a >>> constant, rather than compared to each other. >>

ANNOUNCE: libmsgque 3.4

2009-07-02 Thread Andreas Otto
Dear Users, I would like to provide a new !! Major Feature Release !! of >>> LibMsgque (3.4) <<< This Release Introduce a new technology called >>> Master / Slave - Link <<< and is used to create, mange and configure a MESH of node's (process or thread) distributed o

Re: question of style

2009-07-02 Thread Lie Ryan
Paul Rubin wrote: > Tim Harig writes: >> That being the case, it might be a good idea either to handle the situation >> and raise an exception or add: >> >> assert self.lower <= self.higher >> >> That way an exception will be raised if there is an error somewhere else >> in the code rather then si

Re: Sequence splitting

2009-07-02 Thread Rickard Lindberg
> I tried posting on python-ideas and received a "You are not allowed to > post to this mailing list" reply. Perhaps because I am posting through > Google groups? Or maybe one must be an approved member to post? If you got an "awaiting moderator approval" message you post might appear on the list

Re: question of style

2009-07-02 Thread Lie Ryan
Simon Forman wrote: > Hey I was hoping to get your opinions on a sort of minor stylistic > point. > These two snippets of code are functionally identical. Which would you > use and why? If self is an object (and it must have been), it would be preferrable to set self.higher and self.lower to a kno

<    1   2