Re: A gotcha: Python pain point?

2007-06-12 Thread Terry Reedy
Beorn [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] | Consider this example: | | def funcs(x): | ... for i in range(5): | ... def g(): return x + i | ... yield g | | I would expect the value of x used in g to be that at the function | declaration time, as if

Re: A gotcha: Python pain point?

2007-06-12 Thread Diez B. Roggisch
James Stroud wrote: Beorn wrote: Consider this example: def funcs(x): ... for i in range(5): ... def g(): return x + i ... yield g I would expect the value of x used in g to be that at the function declaration time, as if you've pass g a (x=x) argument,

Re: A gotcha: Python pain point?

2007-06-12 Thread Terry Reedy
James Stroud [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] | Beorn wrote: | Consider this example: | | def funcs(x): |... for i in range(5): |... def g(): return x + i |... yield g | | [ fun() for fun in list(funcs(1)) ] |[5, 5, 5, 5, 5]

Re: A gotcha: Python pain point?

2007-06-12 Thread Diez B. Roggisch
Beorn wrote: Consider this example: def funcs(x): ... for i in range(5): ... def g(): return x + i ... yield g I would expect the value of x used in g to be that at the function You mean i here, don't you? declaration time, as if you've pass g a (x=x)

Re: A gotcha: Python pain point?

2007-06-12 Thread Marc 'BlackJack' Rintsch
In [EMAIL PROTECTED], Terry Reedy wrote: | Should I import this to see how | many principles this behavior violates? ??? If you meant 'report' (on SF), please do not. I think he meant ``import this`` at the Python interpreter. Ciao, Marc 'BlackJack' Rintsch --

Re: A gotcha: Python pain point?

2007-06-12 Thread Beorn
On Jun 12, 5:00 pm, Diez B. Roggisch [EMAIL PROTECTED] wrote: Beorn wrote: [...] I can see how it works now, but I haven't found an easy-to-read documentation on this. This has been discussed here very often. Python closures do capture the names, not the values. If you want a value at a

A gotcha: Python pain point?

2007-06-11 Thread Beorn
Consider this example: def funcs(x): ... for i in range(5): ... def g(): return x + i ... yield g I would expect the value of x used in g to be that at the function declaration time, as if you've pass g a (x=x) argument, especially after reading this post:

Re: A gotcha: Python pain point?

2007-06-11 Thread James Stroud
Beorn wrote: Consider this example: def funcs(x): ... for i in range(5): ... def g(): return x + i ... yield g I would expect the value of x used in g to be that at the function declaration time, as if you've pass g a (x=x) argument, especially after

Re: A gotcha: Python pain point?

2007-06-11 Thread Jean-Paul Calderone
On Mon, 11 Jun 2007 16:54:10 -0700, James Stroud [EMAIL PROTECTED] wrote: Beorn wrote: Consider this example: def funcs(x): ... for i in range(5): ... def g(): return x + i ... yield g [snip] If this isn't classified as a bug, then someone has some serious