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
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,
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]
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)
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
--
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
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:
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
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