nested-scopes redux

Cliff Wells logiplexsoftware at
Thu Sep 13 00:45:17 CEST 2001

Sorry to bring this subject back up again, but I just noticed a somewhat 
annoying feature of the current nested-scope implementation.  One of the big 
pluses of nested scopes is doing away with default arguments in lambda 
functions.  Unfortunately the following bits of code behave differently:

foo = []
for i in [1, 2]:
    foo.append(lambda i = i: i)


from __future__ import nested_scopes
foo = []
for i in [1, 2]:
    foo.append(lambda: i)

In the first case the output from foo[0]() and foo[1]() is 1 and 2, 
respectively - and it's what one would probably want.  In the second case, 
the output is always 2.  This may be the expected behavior, but it kind of 
does away with the benefits to providing a cleaner lambda call.

Cliff Wells
Software Engineer
Logiplex Corporation (
(503) 978-6726 x308
(800) 735-0555 x308

More information about the Python-list mailing list