[Python-ideas] Unify global and nonlocal

Manuel Cerón ceronman at gmail.com
Mon Feb 24 19:17:08 CET 2014


On Mon, Feb 24, 2014 at 4:22 AM, Saket Dandawate <newton3143 at gmail.com> wrote:
> Also why can't it be like this too
>>>> global x = 3
>
> rather than only
>>>> global x
>>>> x=3

I can't find the discussion thread, but originally PEP3104 proposed
this kind of syntax for nonlocal, but it was never actually
implemented because of ambiguity with the unpacking assignment case:

nonlocal x, y, z = 1, 2, 3

Does this mean that x, y and z are non locals? or just x?

Now I understand the differences between nonlocal and global. But
still is not very clear for me why nonlocal can't access the global
module namespace as well, not to be used in the same way as global,
but to access names already defined in the global namespace.

Manuel.


More information about the Python-ideas mailing list