Re: How does this work?

2011-06-04 Thread Ben Finney
Jon Clements writes: > On Jun 5, 4:37 am, Ben Finney wrote: > > writes: > > > (http://stackoverflow.com/questions/312443/how-do-you-split-a-list-int...) > > > > This is an excellent example of why “clever” code is to be shunned. > > Whoever wrote this needs to spend more time trying to get thei

Re: How does this work?

2011-06-04 Thread Jon Clements
On Jun 5, 4:37 am, Ben Finney wrote: > writes: > > I was surfing around looking for a way to split a list into equal > > sections. I came upon this algorithm: > > > >>> f = lambda x, n, acc=[]: f(x[n:], n, acc+[(x[:n])]) if x else acc > > >>> f("Hallo Welt", 3) > > ['Hal', 'lo ', 'Wel', 't'] > >

RE: A simple way to print few line stuck to the same position

2011-06-04 Thread Sarcar, Shourya C (GE Healthcare)
A way to do this on DOS/Windows console would be: import sys for r in range(0,2**16): line = "Count : %d" % r sys.stdout.write(line) sys.stdout.flush() # do something that consumes time backup = "\b" * len(line) # The backspace character; this will prevent c

Re: How does this work?

2011-06-04 Thread Ben Finney
writes: > I was surfing around looking for a way to split a list into equal > sections. I came upon this algorithm: > > >>> f = lambda x, n, acc=[]: f(x[n:], n, acc+[(x[:n])]) if x else acc > >>> f("Hallo Welt", 3) > ['Hal', 'lo ', 'Wel', 't'] > > (http://stackoverflow.com/questions/312443/how-do

How does this work?

2011-06-04 Thread jyoung79
I was surfing around looking for a way to split a list into equal sections. I came upon this algorithm: >>> f = lambda x, n, acc=[]: f(x[n:], n, acc+[(x[:n])]) if x else acc >>> f("Hallo Welt", 3) ['Hal', 'lo ', 'Wel', 't'] (http://stackoverflow.com/questions/312443/how-do-you-split-a-list-int

Re: Generator Frustration

2011-06-04 Thread Jack Diederich
On Sat, Jun 4, 2011 at 9:43 PM, Gregory Ewing wrote: > Steven D'Aprano wrote: > >> A nice piece of syntax that has been proposed for Python is "yield from", >> which will do the same thing, but you can't use that yet. You can also patch the library to always return lists instead of generators. d

Re: float("nan") in set or as key

2011-06-04 Thread Steven D'Aprano
On Sat, 04 Jun 2011 16:49:40 -0500, Robert Kern wrote: > Steven is being a little hyperbolic. Python does not fully conform to > all of the details of the IEEE-754 specification, though it does conform > to most of them. I'm not sure that "most" is correct, but that depends on how you count the

Re: Generator Frustration

2011-06-04 Thread Gregory Ewing
Steven D'Aprano wrote: A nice piece of syntax that has been proposed for Python is "yield from", which will do the same thing, but you can't use that yet. Unless you're impatient enough to compile your own Python with my patch applied: http://www.cosc.canterbury.ac.nz/greg.ewing/python/yield-

Re: how to avoid leading white spaces

2011-06-04 Thread Steven D'Aprano
On Sat, 04 Jun 2011 21:02:32 +0100, Nobody wrote: > On Sat, 04 Jun 2011 05:14:56 +, Steven D'Aprano wrote: > >> This fails to support non-ASCII letters, and you know quite well that >> having to spell out by hand regexes in both upper and lower (or mixed) >> case is not support for case-insen

Re: Generator Frustration

2011-06-04 Thread Steven D'Aprano
On Sat, 04 Jun 2011 14:27:32 -0400, TommyVee wrote: > I'm using the SimPy package to run simulations. Anyone who's used this > package knows that the way it simulates process concurrency is through > the clever use of yield statements. Some of the code in my programs is > very complex and contains

Re: how to avoid leading white spaces

2011-06-04 Thread Steven D'Aprano
On Sat, 04 Jun 2011 09:39:24 -0400, Roy Smith wrote: > To be sure, if you explore the edges of the regex syntax space, you can > write non-portable expressions. You don't even have to get very far out > to the edge. But, as you say, if you limit yourself to a subset, you > can write portable one

Re: A simple way to print few line stuck to the same position

2011-06-04 Thread Hans Mulder
On 4/06/11 13:14:05, TheSaint wrote: Hans Mulder wrote: A minimalist solution would be to print the labels ("This count", etc.) only once, and position the cursor after it to update the report. Generally a good point. Similar sequences are working for coloring and formatting text. As I sa

Re: except KeyError, everywhere --> memoization

2011-06-04 Thread Wilbert Berendsen
Hi, Many thanks for everyone's explanations and pointers! thanks! Wilbert Berendsen -- http://www.wilbertberendsen.nl/ "You must be the change you wish to see in the world." -- Mahatma Gandhi -- http://mail.python.org/mailman/listinfo/python-list

Re: float("nan") in set or as key

2011-06-04 Thread Robert Kern
On 6/4/11 4:28 PM, Ethan Furman wrote: Steven D'Aprano wrote: On Fri, 03 Jun 2011 23:04:38 -0700, Ethan Furman wrote: Steven D'Aprano wrote: NANs are not necessarily errors, they're hardly silent, and if you don't want NANs, the standard mandates that there be a way to turn them off. So how

Re: float("nan") in set or as key

2011-06-04 Thread Ethan Furman
Steven D'Aprano wrote: On Fri, 03 Jun 2011 23:04:38 -0700, Ethan Furman wrote: Steven D'Aprano wrote: NANs are not necessarily errors, they're hardly silent, and if you don't want NANs, the standard mandates that there be a way to turn them off. So how does one turn them off in standard Pytho

Re: how to avoid leading white spaces

2011-06-04 Thread Nobody
On Sat, 04 Jun 2011 05:14:56 +, Steven D'Aprano wrote: > This fails to support non-ASCII letters, and you know quite well that > having to spell out by hand regexes in both upper and lower (or mixed) > case is not support for case-insensitive matching. That's why Python's re > has a case in

Re: Determine attributes of calling method

2011-06-04 Thread Ian Kelly
On Fri, Jun 3, 2011 at 2:35 PM, Joe wrote: >    foo.__dict__['color']='blue' >    fu.__dict__['color']='red' You don't need to use __dict__ to set function attributes. Just do: foo.color = 'blue' -- http://mail.python.org/mailman/listinfo/python-list

Re: how to avoid leading white spaces

2011-06-04 Thread Nobody
On Sat, 04 Jun 2011 13:41:33 +1200, Gregory Ewing wrote: >> Python might be penalized by its use of Unicode here, since a >> Boyer-Moore table for a full 16-bit Unicode string would need >> 65536 entries > > But is there any need for the Boyer-Moore algorithm to > operate on characters? > > Seem

Re: Lambda question

2011-06-04 Thread Vito 'ZeD' De Tullio
jyoun...@kc.rr.com wrote: > I was surfing around looking for a way to split a list into equal > sections. non-recursive, same-unreadeable (worse?) one liner alternative: def chunks(s, j): return [''.join(filter(None,c))for c in map(None,*(s[i::j]for i in range(j)))] -- By ZeD -- http:/

Re: float("nan") in set or as key

2011-06-04 Thread Nobody
On Sat, 04 Jun 2011 00:52:17 -0700, rusi wrote: >> If you're "fluent" in IEEE-754, then you won't find its behaviour >> unexpected. OTOH, if you are approach the issue without preconceptions, >> you're likely to notice that you effectively have one exception mechanism >> for floating-point and ano

Re: Lambda question

2011-06-04 Thread Ian Kelly
On Sat, Jun 4, 2011 at 12:09 PM, Chris Angelico wrote: > Python doesn't seem to have an inbuilt function to divide strings in > this way. At least, I can't find it (except the special case where n > is 1, which is simply 'list(string)'). Pike allows you to use the > division operator: "Hello, worl

Generator Frustration

2011-06-04 Thread TommyVee
I'm using the SimPy package to run simulations. Anyone who's used this package knows that the way it simulates process concurrency is through the clever use of yield statements. Some of the code in my programs is very complex and contains several repeating sequences of yield statements. I want

Re: Lambda question

2011-06-04 Thread Mel
jyoun...@kc.rr.com wrote: > I was surfing around looking for a way to split a list into equal > sections. I came upon this algorithm: > f = lambda x, n, acc=[]: f(x[n:], n, acc+[(x[:n])]) if x else acc f("Hallo Welt", 3) > ['Hal', 'lo ', 'Wel', 't'] > > http://stackoverflow.com/ques

Re: Lambda question

2011-06-04 Thread Chris Angelico
On Sun, Jun 5, 2011 at 3:46 AM, wrote: > It doesn't work with a huge list, but looks like it could be handy in certain > circumstances.  I'm trying to understand this code, but am totally lost.  I > know a little bit about lambda, as well as the ternary operator, but how > does this part work: >

Lambda question

2011-06-04 Thread jyoung79
I was surfing around looking for a way to split a list into equal sections. I came upon this algorithm: >>> f = lambda x, n, acc=[]: f(x[n:], n, acc+[(x[:n])]) if x else acc >>> f("Hallo Welt", 3) ['Hal', 'lo ', 'Wel', 't'] http://stackoverflow.com/questions/312443/how-do-you-split-a-list

how update MultipartPostHandler pypi

2011-06-04 Thread sergio
Hi, As Wrote in http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/146306 http://pypi.python.org/pypi/MultipartPostHandler/0.1.0 is not updated , the author email doesn't not exist , how I send a comment update MultipartPostHandler anyway patch attach -- Sérgio M.B. Only in MultipartPostHan

Re: how to avoid leading white spaces

2011-06-04 Thread rusi
The efficiently argument is specious. [This is a python list not a C or assembly list] The real issue is that complex regexes are hard to get right -- even if one is experienced. This is analogous to the fact that knotty programs can be hard to get right even for experienced programmers. The anal

Re: py2exe: executable is slower than code run from the interpreter

2011-06-04 Thread Miki Tebeka
One thing that comes to mind is importing. py2exe packs libraries in a zip file so importing might be a bit slower. But this should slow only at the beginning until everything is loaded to memory. The other usual suspect is the anti virus :) -- http://mail.python.org/mailman/listinfo/python-lis

py2exe: executable is slower than code run from the interpreter

2011-06-04 Thread Massi
Hi everyone, I'm writing a big program (windows 7, python 2.6.6) which includes lots of python libraries (SQLalchemy, PyQt, SocketServer, Matplotlib,...). Now I'm trying to build a stand alone executable with py2exe (0.6.9) and everything works great. The only issue is that the executable seems to

Re: how to avoid leading white spaces

2011-06-04 Thread Roy Smith
I wrote: >> Another nice thing about regexes (as compared to string methods) is >> that they're both portable and serializable. You can use the same >> regex in Perl, Python, Ruby, PHP, etc. In article <4de9bf50$0$29996$c3e8da3$54964...@news.astraweb.com>, Steven D'Aprano wrote: > Regexes a

how update MultipartPostHandler pypi

2011-06-04 Thread none
Hi, As Wrote in http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/146306 http://pypi.python.org/pypi/MultipartPostHandler/0.1.0 is not updated , the author email doesn't not exist , how I send a comment update MultipartPostHandler anyway patch attach Only in MultipartPostHandler-0.1.0: buil

Re: Determine attributes of calling method

2011-06-04 Thread Richard Thomas
On Jun 3, 9:35 pm, Joe wrote: > Hello, > > I'm trying to implement a way to restrict method usage based on the > caller's attributes.  In the following example I'd like to execute the > server method "bar" only if the caller's method has a "blue" value for > it's color attribute. > > The current o

Re: A simple way to print few line stuck to the same position

2011-06-04 Thread TheSaint
Hans Mulder wrote: > A minimalist solution would be to print the labels ("This count", etc.) > only once, and position the cursor after it to update the report. Generally a good point. Similar sequences are working for coloring and formatting text. I don't know whether the program would behave t

Re: float("nan") in set or as key

2011-06-04 Thread Ben Finney
Steven D'Aprano writes: > What makes you think that Python supports IEEE-754 for floats? That would be an easy impression to get from this long rambling thread. The argument that Python's ‘float’ type is not meant to be anything *but* an IEEE 754 floating point type has been made several times.

Re: float("nan") in set or as key

2011-06-04 Thread Steven D'Aprano
On Fri, 03 Jun 2011 23:04:38 -0700, Ethan Furman wrote: > Steven D'Aprano wrote: >> NANs are not necessarily errors, they're hardly silent, and if you >> don't want NANs, the standard mandates that there be a way to turn them >> off. > > So how does one turn them off in standard Python? Turn the

Re: python + php encrypt/decrypt

2011-06-04 Thread hidura
Use xml to pass the encrypt text. On , Peter Irbizon wrote: Hello, I would like to encrypt text in python and decrypt it in my PHP script. I tried to use pycrypto and some aes php scripts but the results are not the same. Please, is there any example (the best way source codes) how to

Re: float("nan") in set or as key

2011-06-04 Thread rusi
On Jun 4, 4:29 am, Nobody wrote: > On Fri, 03 Jun 2011 14:52:39 +, Grant Edwards wrote: > >> It's arguable that NaN itself simply shouldn't exist in Python; if > >> the FPU ever generates a NaN, Python should raise an exception at > >> that point. > > > If you're "fluent" in IEEE-754, then yo

python + php encrypt/decrypt

2011-06-04 Thread Peter Irbizon
Hello, I would like to encrypt text in python and decrypt it in my PHP script. I tried to use pycrypto and some aes php scripts but the results are not the same. Please, is there any example (the best way source codes) how to do this in python and PHP? -- http://mail.python.org/mailman/listinfo/p

python + php encrypt/decrypt

2011-06-04 Thread miamia
Hello, I would like to encrypt text in python and decrypt it in my PHP script. I tried to use pycrypto and some aes php scripts but the results are not the same. Please, is there any example (the best way source codes) how to do this in python and PHP? many thanks -- http://mail.python.org/mailman