Re: why memoizing is faster

2011-03-25 Thread Terry Reedy
On 3/26/2011 12:17 AM, Stefan Behnel wrote: Not "restarted" in the sense that it gets cleaned up, though. The above simply passes an explicit value for it that will be used for the single call. Which satisfies the time test need, but... > Future calls won't be affected. Good point. If one do

Re: best python games?

2011-03-25 Thread Dan Stromberg
On Fri, Mar 25, 2011 at 7:39 PM, sogeking99 wrote: > hey guys, what are some of the best games made in python? free games > really. like pygames stuff. i want to see what python is capable of. > > cant see any good one on pygames site really, though they have nothing > like sort by rating or most

Re: why memoizing is faster

2011-03-25 Thread Stefan Behnel
Terry Reedy, 25.03.2011 21:18: On 3/25/2011 5:16 AM, Stefan Behnel wrote: Terry's version is playing with the fact that default arguments are only instantiated once, i.e. (unless overridden by passing an explicit argument) the "_cache" is shared over all calls to the function. This is similar t

Re: historic grail python browser "semi-recovered"

2011-03-25 Thread Juno
Hi, Luke Leighton... Maybe I can help... ... Mugs Globe Life Insurance $1* Buys $50,000 Life Insurance. Adults or Children. No Medical Exam. http://thirdpartyoffers.juno.com/TGL3141/4d8d53ea5a2d5414007st02duc-- http://mail.python.org/m

Re: best python games?

2011-03-25 Thread Corey Richardson
On 03/25/2011 10:39 PM, sogeking99 wrote: > hey guys, what are some of the best games made in python? free games > really. like pygames stuff. i want to see what python is capable of. > > cant see any good one on pygames site really, though they have nothing > like sort by rating or most downloade

passing c_void_p to an library(.so) to c function

2011-03-25 Thread OJ
Hi I am trying to implement a python frontend for a c library. I can open the library successfully and call functions using ctypes. My challenge now is that this library are using plugins, which is also libraries (.so on linux). The library function for adding these plugins expects a viod * to the

best python games?

2011-03-25 Thread sogeking99
hey guys, what are some of the best games made in python? free games really. like pygames stuff. i want to see what python is capable of. cant see any good one on pygames site really, though they have nothing like sort by rating or most downloaded as far as i can tell -- http://mail.python.org/ma

Re: Writing to a file

2011-03-25 Thread eryksun ()
On Friday, March 25, 2011 9:39:11 PM UTC-4, Littlefield, Tyler wrote: > >with open(test_absname, 'w') as test: > what's the difference in that and test = ...? I can see why you > mentioned the os.path for cross-platform, but I don't understand why > someone would use with over =. It avoids h

C Callback Function using ctypes

2011-03-25 Thread OJ
Hi I am opening a shared library which has defined the following callback prototype: extern void DebugMessage(int level, const char *message, ...); My implementation in Python looks like this: DEBUGFUNC = ctypes.CFUNCTYPE(None, ctypes.c_int, ctypes.POINTER(ctypes.c_char)) def DebugMessage(lvl, msg

Re: Writing to a file

2011-03-25 Thread Dan Stromberg
with closes the file for you, when the indented block is exited. ~ isn't cross-platform at all, in fact it's not precisely python, though os.path.expanduser understands it. AFAIK, the jury's still out on whether the /'s in pathnames as directory separators are portable. I know they work on *ix a

Re: Dump interpreter history?

2011-03-25 Thread Tim Chase
On 03/25/2011 04:40 PM, Daniel Mahoney wrote: On Fri, 25 Mar 2011 17:03:55 -0400, Ken D'Ambrosio wrote: Hey, all. A co-worker asked me a question, and I've got no idea how (or if) it can be done. Bottom line: he'd like to save off the text from an interpreter session, his thinking being that

Re: Writing to a file

2011-03-25 Thread Gregory Ewing
jyoun...@kc.rr.com wrote: import os os.system('echo "Testing a... b... c..." > "~/Desktop/test2.txt"') This is like going out the back door, getting a ladder out of the shed and climbing through your bedroom window to get into bed at night, instead of just using the stairs. Use open/write/clo

Re: Writing to a file

2011-03-25 Thread Gregory Ewing
John Gordon wrote: The write() way is much better. (However, I'm not sure it will do what you were expecting with the tilde in the file path.) It won't, but the os.path.expanduser() function can be used to fix that. -- Greg -- http://mail.python.org/mailman/listinfo/python-list

Re: Writing to a file

2011-03-25 Thread Littlefield, Tyler
>with open(test_absname, 'w') as test: what's the difference in that and test = ...? I can see why you mentioned the os.path for cross-platform, but I don't understand why someone would use with over =. On 3/25/2011 7:11 PM, eryksun () wrote: On Friday, March 25, 2011 11:07:19 AM UTC-4, jy

Re: Writing to a file

2011-03-25 Thread eryksun ()
On Friday, March 25, 2011 11:07:19 AM UTC-4, jyou...@kc.rr.com wrote: > > >>> f = open('~/Desktop/test.txt', 'w') > >>> f.write('testing 1... 2... 3...') > >>> f.close() Consider using "with" to automatically close the file and os.path for cross-platform compatibility: import os.path use

Re: Dump interpreter history?

2011-03-25 Thread Dan Mahoney
Yeah, sorry about that. The square brackets were supposed to indicate that filename is an optional argument. If not supplied, defaults to .history. Dan Mahoney catd...@gmail.com Sent from my Android phone On Mar 25, 2011 6:57 PM, "Tim Chase" wrote: On 03/25/2011 04:40 PM, Daniel Mahoney wrote:

Re: Where to put .pth files on slax

2011-03-25 Thread Tim Johnson
* Tim Johnson [110325 12:59]: > Hello: I'm trying to put together a test platform on a slax OS. > Python 2.7 packages appear to be at /user/lib/python2.7. > > Where is the appropriate place to put a .pth file? I must have stumped the chumps. And this chump hasn't used pth files in a coon's age

Re: Converting an array of string to array of float

2011-03-25 Thread Blockheads Oi Oi
Thanks Bruno. I just missed it. I got it back and thanks Blockhead for giving me new angle to look into the problem. Best Regards, Subhabrata. Nothing personal, but it's Blockheads (plural) AND you missed the OI OI. What is the problem with modern day education? :) -- http://mail.python.org

Re: python 2.7.1 "serial" vs "pyserial"

2011-03-25 Thread eryksun ()
On 3/25/2011 7:27 AM, bruce bushby wrote: > > Is there any difference between the "serial" module in Python 2.7.1 and > "pyserial 2.5" ? I've never used it, but "pyserial" is actually "serial": http://pyserial.sourceforge.net I have it installed on my system via Christoph Gohlke's "Base" distri

Re: Guido rethinking removal of cmp from sort method

2011-03-25 Thread Dan Stromberg
On Sun, Mar 13, 2011 at 5:59 AM, Steven D'Aprano < steve+comp.lang.pyt...@pearwood.info> wrote: > The removal of cmp from the sort method of lists is probably the most > disliked change in Python 3. On the python-dev mailing list at the > moment, Guido is considering whether or not it was a mistak

Re: Converting an array of string to array of float

2011-03-25 Thread Algis Kabaila
On Saturday 26 March 2011 02:27:12 Jason Swails wrote: > I'm guessing you have something like > > list1=['1.0', '2.3', '4.4', '5.5', ...], right? > > You can do this: > > for i in range(len(list1)): > list1[i] = float(list1[i]) Better, list1 = [float(v) for v in list1] One statement only -

Re: Guido rethinking removal of cmp from sort method

2011-03-25 Thread Carl Banks
On Mar 25, 3:06 pm, Steven D'Aprano wrote: > The reason Guido is considering re-introducing cmp is that somebody at > Google approached him with a use-case where a key-based sort did not > work. The use-case was that the user had masses of data, too much data > for the added overhead of Decorate-S

Re: dynamic assigments

2011-03-25 Thread Steven D'Aprano
On Fri, 25 Mar 2011 13:29:20 +0100, Seldon wrote: > On 03/25/2011 12:05 AM, Steven D'Aprano wrote: >> On Thu, 24 Mar 2011 19:39:21 +0100, Seldon wrote: >> >>> Hi, I have a question about generating variable assignments >>> dynamically. >> [...] >>> Now, I would like to use data contained in this l

Re: Guido rethinking removal of cmp from sort method

2011-03-25 Thread Steven D'Aprano
On Fri, 25 Mar 2011 13:56:23 +0100, Antoon Pardon wrote: > Look we are provided with the cmp_to_key function. If something doesn't > work with that function or performs realy bad with that function, it > means either the function has a bug in it or something the function > relies on, has a bug in

Re: Converting an array of string to array of float

2011-03-25 Thread Steven D'Aprano
On Fri, 25 Mar 2011 08:19:24 -0700, joy99 wrote: > Dear Group, > > I got a question which might be possible but I am not getting how to do > it. > > If I have a list, named, > list1=[1.0,2.3,4.4,5.5] That looks like a list of floats already. Perhaps you meant: list1 = ["1.0", "2.3", "4.4",

Re: dynamic assigments

2011-03-25 Thread Steven D'Aprano
On Fri, 25 Mar 2011 02:47:04 -0700, scattered wrote: > I specified that the cipher text consists of characters in the range A > to Z (note the case). So you did. My apologies. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Guido rethinking removal of cmp from sort method

2011-03-25 Thread Steven D'Aprano
On Fri, 25 Mar 2011 10:21:35 +0100, Antoon Pardon wrote: > On Thu, Mar 24, 2011 at 11:49:53PM +, Steven D'Aprano wrote: >> On Thu, 24 Mar 2011 17:47:05 +0100, Antoon Pardon wrote: >> >> > However since that seems to be a problem for you I will be more >> > detailed. The original poster didn't

Re: Dump interpreter history?

2011-03-25 Thread Calvin Spealman
Tell your coworker that what he should be doing is writing good tests, which he can rerun repeatedly while working towards a solution. Instead of writing a new function in an interpreter, he can add tests to confirm how he wants it to behave and then keep working on it unitl those tests pass. On F

Re: Dump interpreter history?

2011-03-25 Thread Daniel Mahoney
On Fri, 25 Mar 2011 17:03:55 -0400, Ken D'Ambrosio wrote: > Hey, all. A co-worker asked me a question, and I've got no idea how (or > if) it can be done. Bottom line: he'd like to save off the text from an > interpreter session, his thinking being that you've already tried to get > what you want

Re: Dump interpreter history?

2011-03-25 Thread John Gordon
In "Ken D'Ambrosio" writes: > Hey, all. A co-worker asked me a question, and I've got no idea how (or > if) it can be done. Bottom line: he'd like to save off the text from an > interpreter session, his thinking being that you've already tried to get > what you want, and now you just need to

Re: Dump interpreter history?

2011-03-25 Thread FELD Boris
Take a look at : http://ipython.scipy.org/doc/manual/html/interactive/tutorial.html#use-your-input-history Cheers, FELD Boris -- FELD Boris Sent with Sparrow On vendredi 25 mars 2011 at 22:03, Ken D'Ambrosio wrote: > Hey, all. A co-worker asked me a question, and I've got no idea how (or > if)

Re: Dump interpreter history?

2011-03-25 Thread Brian Curtin
On Fri, Mar 25, 2011 at 16:03, Ken D'Ambrosio wrote: > Hey, all. A co-worker asked me a question, and I've got no idea how (or > if) it can be done. Bottom line: he'd like to save off the text from an > interpreter session, his thinking being that you've already tried to get > what you want, an

Dump interpreter history?

2011-03-25 Thread Ken D'Ambrosio
Hey, all. A co-worker asked me a question, and I've got no idea how (or if) it can be done. Bottom line: he'd like to save off the text from an interpreter session, his thinking being that you've already tried to get what you want, and now you just need to gussy it up in an editor. Can this be d

Where to put .pth files on slax

2011-03-25 Thread Tim Johnson
Hello: I'm trying to put together a test platform on a slax OS. Python 2.7 packages appear to be at /user/lib/python2.7. Where is the appropriate place to put a .pth file? Note, I have django on this system too, but slax does not resolved system paths. And that is 'slax' not 'slack'. -- Tim tim

Re: python 2.7.1 "serial" vs "pyserial"

2011-03-25 Thread Terry Reedy
On 3/25/2011 7:27 AM, bruce bushby wrote: Hi Is there any difference between the "serial" module in Python 2.7.1 and "pyserial 2.5" ? When asking about 3rd party modules, it may help to give a reference to the site or download page on pypi. (And one should also check to package specific list

Re: why memoizing is faster

2011-03-25 Thread Terry Reedy
On 3/25/2011 5:16 AM, Stefan Behnel wrote: Terry's version is playing with the fact that default arguments are only instantiated once, i.e. (unless overridden by passing an explicit argument) the "_cache" is shared over all calls to the function. This is similar to what your memoization decorato

Re: why memoizing is faster

2011-03-25 Thread Terry Reedy
On 3/25/2011 4:49 AM, Andrea Crotti wrote: Terry Reedy writes: def fib_iter(n, _cache = [1,1]): k = len(_cache) if n>= k: for i in range(k, n+1): _cache.append(_cache[i-2] + _cache[i-1]) return _cache[n] I just realized that the signature really ought to be def fib_i

Re: Reading/Writing files

2011-03-25 Thread Dan Stromberg
On Fri, Mar 25, 2011 at 6:42 AM, Westley Martínez wrote: > > > > I argue that the first is quite a bit more readable than the second: > > > 'c:/temp/choose_python.pdf' > > > os.path.join([ 'c:', 'temp', 'choose_python.pdf' ]) > > > > I agree with your argument, but think that > > r'c:\tem

Re: dynamic assigments

2011-03-25 Thread Carl Banks
On Mar 25, 5:29 am, Seldon wrote: > I thought to refactor the code in a more declarative way, like > > assignment_list = ( > ('var1', value1), > ('var2', value2), > .. , > ) > > for (variable, value) in assignment_list: >         locals()[variable] = func(arg=value, *args) Someday we'll get throu

Re: embedding interactive python interpreter

2011-03-25 Thread Eric Frederich
Added a fflush(stdout) after each printf and, as I expectedstill only the first 2 prints. On Fri, Mar 25, 2011 at 1:47 PM, MRAB wrote: > On 25/03/2011 17:37, Eric Frederich wrote: >> >> So I found that if I type ctrl-d then the other lines will print. >> >> It must be a bug then that the

Re: embedding interactive python interpreter

2011-03-25 Thread MRAB
On 25/03/2011 17:37, Eric Frederich wrote: So I found that if I type ctrl-d then the other lines will print. It must be a bug then that the exit() function doesn't do the same thing. The documentation says "The return value will be the integer passed to the sys.exit() function" but clearly n

Re: embedding interactive python interpreter

2011-03-25 Thread Eric Frederich
So I found that if I type ctrl-d then the other lines will print. It must be a bug then that the exit() function doesn't do the same thing. The documentation says "The return value will be the integer passed to the sys.exit() function" but clearly nothing is returned since the call to Py_Main

Re: Converting an array of string to array of float

2011-03-25 Thread joy99
On Mar 25, 9:19 pm, "bruno.desthuilli...@gmail.com" wrote: > On 25 mar, 16:19, joy99 wrote: > > > > > Dear Group, > > > I got a question which might be possible but I am not getting how to > > do it. > > > If I have a list, named, > > list1=[1.0,2.3,4.4,5.5] > > > Now each element in the arra

Re: Converting an array of string to array of float

2011-03-25 Thread bruno.desthuilli...@gmail.com
On 25 mar, 16:19, joy99 wrote: > Dear Group, > > I got a question which might be possible but I am not getting how to > do it. > > If I have a list, named, > list1=[1.0,2.3,4.4,5.5] > > Now each element in the array holds the string property if I want to > convert them to float, how would I do

Re: Converting an array of string to array of float

2011-03-25 Thread Blockheads Oi Oi
On 25/03/2011 15:46, Rafael Durán Castañeda wrote: But you must be sure that the list only contains objects than can be converted into float, if not you'll get: >>> float('something') Traceback (most recent call last): File "", line 1, in float('something') ValueError: could not conver

Re: Writing to a file

2011-03-25 Thread Adam Tauno Williams
On Fri, 2011-03-25 at 15:07 +, jyoun...@kc.rr.com wrote: > Just curious how others view the 2 examples below for creating and > writing to a file in Python (in OS X). Is one way better than the other? > If it was a large amount of text, would the 'os.system' call be a bad > way to do it?

Re: Writing to a file

2011-03-25 Thread John Gordon
In writes: > Just curious how others view the 2 examples below for creating and > writing to a file in Python (in OS X). Is one way better than the other? > If it was a large amount of text, would the 'os.system' call be a bad > way to do it? The write() way is much better. (However, I'm

embedding interactive python interpreter

2011-03-25 Thread Eric Frederich
I am able to embed the interactive Python interpreter in my C program except that when the interpreter exits, my entire program exits. #include #include int main(int argc, char *argv[]){ printf("line %d\n", __LINE__); Py_Initialize(); printf("line %d\n", __LI

Re: Converting an array of string to array of float

2011-03-25 Thread Rafael Durán Castañeda
But you must be sure that the list only contains objects than can be converted into float, if not you'll get: >>> float('something') Traceback (most recent call last): File "", line 1, in float('something') ValueError: could not convert string to float: something >>> 2011/3/25 Blockheads O

Re: Converting an array of string to array of float

2011-03-25 Thread Blockheads Oi Oi
On 25/03/2011 15:27, Jason Swails wrote: I'm guessing you have something like list1=['1.0', '2.3', '4.4', '5.5', ...], right? You can do this: for i in range(len(list1)): list1[i] = float(list1[i]) or for i, x in enumerate(list1): list1[i] = float(x) -- http://mail.python.org/mail

Re: Converting an array of string to array of float

2011-03-25 Thread Christoph Brand
If you want to have it even shorter and you are using Python 2.5 or greater you can also use: list1 = [float(list_item) for list_item in list1] Am 25.03.2011 16:27, schrieb Jason Swails: I'm guessing you have something like list1=['1.0', '2.3', '4.4', '5.5', ...], right? You can do this: for

Re: Writing to a file

2011-03-25 Thread cassiope
On Mar 25, 8:07 am, wrote: > Just curious how others view the 2 examples below for creating and > writing to a file in Python (in OS X).  Is one way better than the other?   > If it was a large amount of text, would the 'os.system' call be a bad > way to do it? > > Thanks. > > Jay > > > > >>> f =

Re: Converting an array of string to array of float

2011-03-25 Thread Jason Swails
I'm guessing you have something like list1=['1.0', '2.3', '4.4', '5.5', ...], right? You can do this: for i in range(len(list1)): list1[i] = float(list1[i]) There's almost certainly a 1-liner you can use, but this should work. --Jason On Fri, Mar 25, 2011 at 8:19 AM, joy99 wrote: > Dear G

Re: Converting an array of string to array of float

2011-03-25 Thread Nitin Pawar
did you try type casting with float ? On Fri, Mar 25, 2011 at 8:49 PM, joy99 wrote: > Dear Group, > > I got a question which might be possible but I am not getting how to > do it. > > If I have a list, named, > list1=[1.0,2.3,4.4,5.5] > > Now each element in the array holds the string proper

Converting an array of string to array of float

2011-03-25 Thread joy99
Dear Group, I got a question which might be possible but I am not getting how to do it. If I have a list, named, list1=[1.0,2.3,4.4,5.5] Now each element in the array holds the string property if I want to convert them to float, how would I do it? Extracting the values with for and appendin

Writing to a file

2011-03-25 Thread jyoung79
Just curious how others view the 2 examples below for creating and writing to a file in Python (in OS X). Is one way better than the other? If it was a large amount of text, would the 'os.system' call be a bad way to do it? Thanks. Jay >>> f = open('~/Desktop/test.txt', 'w') >>> f.write('t

Re: "in house" pypi?

2011-03-25 Thread Colin J. Williams
On 24-Mar-11 03:13 AM, John Nagle wrote: On 3/23/2011 8:19 PM, Miki Tebeka wrote: Greetings, My company want to distribute Python packages internally. We would like something like an internal PyPi where people can upload and easy_install from packages. Is there such a ready made solution? I'd

jump to C definition

2011-03-25 Thread Andrea Crotti
While I use emacs, if it knows where the source code is, I can very easily jump to a function definition even if it's in C. I think it would be nice to have something like this also for python, at least to make it easy to explore the code and learn something new, without digging too much into the

Re: Guido rethinking removal of cmp from sort method

2011-03-25 Thread Stefan Behnel
Westley Martínez, 25.03.2011 14:39: On Fri, 2011-03-25 at 07:11 +0100, Stefan Behnel wrote: Steven D'Aprano, 25.03.2011 06:46: On Thu, 24 Mar 2011 18:32:11 -0700, Carl Banks wrote: It's probably the least justified builtin other than pow. I don't know about that. Correctly, efficiently and

Re: Reading/Writing files

2011-03-25 Thread Westley Martínez
On Fri, 2011-03-25 at 05:39 -0700, Ethan Furman wrote: > On 3/18/2011 6:25 PM, Dan Stromberg wrote: > > > > On Fri, Mar 18, 2011 at 4:00 PM, Ethan Furman > > wrote: > > > > Dan Stromberg wrote: > > > > > > Are you on windows? > > > > You probably shou

Re: Guido rethinking removal of cmp from sort method

2011-03-25 Thread Westley Martínez
On Fri, 2011-03-25 at 07:11 +0100, Stefan Behnel wrote: > Steven D'Aprano, 25.03.2011 06:46: > > On Thu, 24 Mar 2011 18:32:11 -0700, Carl Banks wrote: > > > >> It's probably the least justified builtin other than pow. > > > > I don't know about that. Correctly, efficiently and *quickly* > > impleme

Re: dynamic assigments

2011-03-25 Thread Jean-Michel Pichavant
Jean-Michel Pichavant wrote: Seldon wrote: On 03/25/2011 12:05 AM, Steven D'Aprano wrote: On Thu, 24 Mar 2011 19:39:21 +0100, Seldon wrote: Hi, I have a question about generating variable assignments dynamically. [...] Now, I would like to use data contained in this list to dynamically gene

Re: dynamic assigments

2011-03-25 Thread Michael Torrie
On 03/25/2011 06:29 AM, Seldon wrote: > Because I'm in this situation. My current code is of the form: > > var1 = func(arg=value1, *args) > .. > varn = func(arg=valuen, *args) > > where var1,..varn are variable names I know in advance and > value1,..valuen are objects known in advance, too; fun

Re: dynamic assigments

2011-03-25 Thread Jean-Michel Pichavant
Seldon wrote: On 03/25/2011 12:05 AM, Steven D'Aprano wrote: On Thu, 24 Mar 2011 19:39:21 +0100, Seldon wrote: Hi, I have a question about generating variable assignments dynamically. [...] Now, I would like to use data contained in this list to dynamically generate assignments of the form "

Re: Reading/Writing files

2011-03-25 Thread Ethan Furman
On 3/18/2011 6:25 PM, Dan Stromberg wrote: On Fri, Mar 18, 2011 at 4:00 PM, Ethan Furman mailto:et...@stoneleaf.us>> wrote: Dan Stromberg wrote: Are you on windows? You probably should use / as your directory separator in Python, not \. In Python, and most other

Re: Guido rethinking removal of cmp from sort method

2011-03-25 Thread Antoon Pardon
On Fri, Mar 25, 2011 at 11:05:17AM +0100, Stefan Behnel wrote: > Antoon Pardon, 25.03.2011 10:21: > >On Thu, Mar 24, 2011 at 11:49:53PM +, Steven D'Aprano wrote: > >>On Thu, 24 Mar 2011 17:47:05 +0100, Antoon Pardon wrote: > >> > >>>However since that seems to be a problem for you I will be mor

Re: dynamic assigments

2011-03-25 Thread Seldon
On 03/25/2011 12:05 AM, Steven D'Aprano wrote: On Thu, 24 Mar 2011 19:39:21 +0100, Seldon wrote: Hi, I have a question about generating variable assignments dynamically. [...] Now, I would like to use data contained in this list to dynamically generate assignments of the form "var1 = value1",

Re: why memoizing is faster

2011-03-25 Thread Andrea Crotti
"eryksun ()" writes: > See Pep 232: http://www.python.org/dev/peps/pep-0232 > > Also, see the discussion thread on Python-Dev: > > http://mail.python.org/pipermail/python-dev/2000-April/thread.html#3282 > > I don't think self-referenced static variables (as in C's "static" > declaration) are discu

python 2.7.1 "serial" vs "pyserial"

2011-03-25 Thread bruce bushby
Hi Is there any difference between the "serial" module in Python 2.7.1 and "pyserial 2.5" ? I can "import serial" without any issuesbut when I follow code examples my scripts complain: "TypeError: readline() takes no keyword arguments" However lots of scripts "import serial" and then "ser.re

Re: why memoizing is faster

2011-03-25 Thread eryksun ()
On Friday, March 25, 2011 6:53:48 AM UTC-4, Andrea Crotti wrote: > > I had never seen such a thing, but why would this make sense at all? > When does it make sense logically for a function to have an attribute? > > A function should have some input, some local variables to compute > temporary resu

Re: why memoizing is faster

2011-03-25 Thread Andrea Crotti
"eryksun ()" writes: > > Regarding this I have question about function attributes. Is there an > equivalent of 'self' for functions? I've seen people use function > attributes as local static variables, but this seems problematic when > all you have is a global reference to the function. The orig

Re: Guido rethinking removal of cmp from sort method

2011-03-25 Thread Stefan Behnel
Antoon Pardon, 25.03.2011 10:21: On Thu, Mar 24, 2011 at 11:49:53PM +, Steven D'Aprano wrote: On Thu, 24 Mar 2011 17:47:05 +0100, Antoon Pardon wrote: However since that seems to be a problem for you I will be more detailed. The original poster didn't ask for cases in which cmp was necessa

Re: why memoizing is faster

2011-03-25 Thread eryksun ()
On Thursday, March 24, 2011 8:12:22 PM UTC-4, Terry Reedy wrote: > > If Python did what some have asked, which is to make 'recursive' > functions actually recursive by replacing a local variable that matches > the function name (in this 'fib') with a direct reference to the > function itself, as

Re: why memoizing is faster

2011-03-25 Thread Tim Wintle
On Fri, 2011-03-25 at 09:49 +0100, Andrea Crotti wrote: > Terry Reedy writes: > > > > For the reason Stefan explained and hinted above. Try the following instead: > > > > def fib_iter(n, _cache = [1,1]): > > k = len(_cache) > > if n >= k: > > for i in range(k, n+1): > >_cache.appen

Re: dynamic assigments

2011-03-25 Thread scattered
On Mar 25, 1:44 am, Steven D'Aprano wrote: > > In my earlier post, I described the dynamic creation of variables as: > > "... something you should *nearly* always avoid doing." [Emphasis added.] > > Congratulations, you've found one of the few exceptions. Of course an > interactive shell must allo

Re: dynamic assigments

2011-03-25 Thread scattered
On Mar 24, 11:08 pm, Tim Leslie wrote: > On 25 March 2011 13:51, scattered wrote: > > > Here is another possibility: you are using Python *interactively* in > > solving cryptograms (as a matter of fact - I was doing exactly this > > yesterday in trying to solve some Playfair ciphers). You have a

Re: Guido rethinking removal of cmp from sort method

2011-03-25 Thread Antoon Pardon
On Thu, Mar 24, 2011 at 11:49:53PM +, Steven D'Aprano wrote: > On Thu, 24 Mar 2011 17:47:05 +0100, Antoon Pardon wrote: > > > However since that seems to be a problem for you I will be more > > detailed. The original poster didn't ask for cases in which cmp was > > necessary, he asked for case

Re: why memoizing is faster

2011-03-25 Thread Stefan Behnel
Andrea Crotti, 25.03.2011 09:49: Terry Reedy writes: For the reason Stefan explained and hinted above. Try the following instead: def fib_iter(n, _cache = [1,1]): k = len(_cache) if n>= k: for i in range(k, n+1): _cache.append(_cache[i-2] + _cache[i-1]) return _cache[n]

Re: why memoizing is faster

2011-03-25 Thread Andrea Crotti
Terry Reedy writes: > > For the reason Stefan explained and hinted above. Try the following instead: > > def fib_iter(n, _cache = [1,1]): > k = len(_cache) > if n >= k: > for i in range(k, n+1): >_cache.append(_cache[i-2] + _cache[i-1]) > return _cache[n] > > This should be sligh

Re: Problem with keyboard up/down arrows in Python 2.4 interpreter

2011-03-25 Thread Ned Deily
In article , Benjamin Kaplan wrote: > As I stated above, py-readline is for if you're using Macports, which > is a package manager for Mac OS X. ... in which case you probably want: sudo port install py-readline > If you installed Python through > some other means, I'm not sure why you don

Re: functools.partial doesn't work without using named parameter

2011-03-25 Thread Paddy
Aha! Thanks Ian for this new snippet. It is what I will use for my current example. (But please see my third posting on this too). -- http://mail.python.org/mailman/listinfo/python-list

Re: functools.partial doesn't work without using named parameter

2011-03-25 Thread Paddy
Thanks Ian, Benjamin, and Steven. I now know why it works as it does. Thinking about it a little more, Is it reasonable to *expect* partial acts as it does, rather than this way being an implementation convenience? (That was written as a straight question not in any way as a dig). I had though

Re: functools.partial doesn't work without using named parameter

2011-03-25 Thread Ian Kelly
On Fri, Mar 25, 2011 at 1:03 AM, Ian Kelly wrote: > Moral of the story: if you pass in an argument by keyword, then the > following arguments must be passed by keyword as well (or not at all), > regardless of whether you're using partial or not. To be clear, you can also just pass f1 into partial

Re: functools.partial doesn't work without using named parameter

2011-03-25 Thread Steven D'Aprano
On Thu, 24 Mar 2011 23:30:29 -0700, Paddy wrote: > Hi, I just found the following oddity where for function fsf1 I am > forced to use a named parameter for correct evaluation and was wondering > why it doesn't work, yet the example from the docs of wrapping int to > create basetwo doesn't need thi

Re: functools.partial doesn't work without using named parameter

2011-03-25 Thread Ian Kelly
On Fri, Mar 25, 2011 at 12:30 AM, Paddy wrote: def fs(f, s): return [f(value) for value in s] Note that your "fs" is basically equivalent to the "map" builtin, minus some of the features. fsf1 = partial(fs, f=f1) fsf1(s) > Traceback (most recent call last): >  File "", line 1, in

Re: functools.partial doesn't work without using named parameter

2011-03-25 Thread Benjamin Kaplan
On Fri, Mar 25, 2011 at 2:30 AM, Paddy wrote: > Hi, I just found the following oddity where for function fsf1 I am forced to > use a named parameter for correct evaluation and was wondering why it doesn't > work, yet the example from the docs of wrapping int to create basetwo doesn't > need thi

Re: Problem with keyboard up/down arrows in Python 2.4 interpreter

2011-03-25 Thread Benjamin Kaplan
On Fri, Mar 25, 2011 at 2:25 AM, Julien wrote: > On Mar 22, 5:37 pm, Benjamin Kaplan wrote: >> On Tue, Mar 22, 2011 at 2:27 AM, Julien wrote: >> > Hi, >> >> > I'm having problems when typing the up/down arrows in the Python 2.4 >> > interpreter (exact version: Python 2.4.6 (#1, Mar  3 2011, 15:4