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

Alex Martelli aleaxit at
Thu Mar 1 16:46:36 CET 2001

"Jeremy Hylton" <jeremy at> wrote in message
news:mailman.983384008.21434.python-list at
>   Rebinding names in enclosing scopes
>       opposed to it.  It is difficult to support, because it would
>       require a new mechanism that would allow the programmer to specify
>       that an assignment in a block is supposed to rebind the name in an
>       enclosing block; presumably a keyword or special syntax (x := 3)
>       would make this possible.

If this were to be allowed (and I'm not saying it should be!), the
most natural way to allow it would appear to be to be a new clause
on the global statement -- most natural, because "allow rebinding
in an outer scope" is exactly global's job (of course, up to Python
2, the only 'outer scope' was the module-one:-).

Maybe something like...:

    def spam():
        def inner():
            global in spam, x
            x += 1
        x = 23


More information about the Python-list mailing list