[Python-Dev] PEP for Better Control of Nested Lexical Scopes

Almann T. Goo almann.goo at gmail.com
Thu Feb 23 02:12:29 CET 2006


> Oddly, in Python, 'global' isn't actually necessary,
> since the module can always import itself and use
> attribute access.
>
> Clearly, though, Guido must have thought at the time
> that it was worth providing an alternative way.

I believe that use cases for rebinding globals (module attributes)
from within a module are more numerous than rebinding in an enclosing
lexical scope (although rebinding a name in the global scope from a
local scope is really just a specific case of that).  I would think
this was probably a motivator for the 'global' key word to avoid
clumsier workarounds.  Since there were no nested lexical scopes back
then, there was no need to have a construct for arbitrary enclosing
scopes.

-Almann

--
Almann T. Goo
almann.goo at gmail.com


More information about the Python-Dev mailing list