PEP 227 (was Re: Nested scopes resolution -- you can breathe again!)

Tim Peters tim.one at home.com
Thu Mar 1 18:47:58 EST 2001


[Jeremy Hylton]
> Or: global NAME in FUNCTION
>
> def eggs():
>     z = 2
>     def spam():
>         def inner():
>             global x in spam, z in eggs
>             x += 1
>             z += x
>         x = 23
>         inner()

[Robin Becker]
> I like that a lot better than having it default possibly wrongly, but
> how would this be doable/spelled in the lambda case?

Wouldn't.  Python lambdas are restricted to a single expression, and all
(re)binding constructs in Python are (non-expression) statements.  So there's
no possibility to do a binding inside a Python lambda anyway (note that the
point of the above was to provide a means for changing names in outer scopes;
but lambdas can't even bind names in the local scope).





More information about the Python-list mailing list