Excellent explanation by Mark Wooding. I would only like to add that
the standard pythonic idiom in such cases seems to be the (ab)use of a
default argument to the function, because these get evaluated at the
definition time:
def gen0():
for i in range(3):
def gen1(i = i):
Dieter Maurer <[EMAIL PROTECTED]> wrote:
> I met the following surprising behaviour
[code moved until later...]
> The apparent reason is that the free variables in nested generator
> definitions are not bound (to a value) at invocation time but only at
> access time.
No. This is about the diff
On Jul 3, 9:20 pm, "Dieter Maurer" <[EMAIL PROTECTED]> wrote:
> The apparent reason is that the free variables in
> nested generator definitions are not bound (to a value) at invocation
> time but only at access time.
That's what it is supposed to do. Welcome to a dynamic
language.
Raymond
--