[Python-Dev] Explicit Lexical Scoping (pre-PEP?)
Andrew Koenig
ark at acm.org
Sun Jul 9 17:07:56 CEST 2006
> So, if I understand correctly, in the presence of a global statement
> search
> just goes up the lexical chain looking for the first occurrence of the
> variable to modify?
>
> x = 0
> def f():
> x = 1
> def g():
> global x
> x = 2
> print x
> g()
> print x
> f()
> print x
>
> Today it prints
>
> 2
> 1
> 2
>
> You're suggesting it will print
>
> 2
> 2
> 0
>
> ?
Sounds right to me.
> Sounds reasonable to me. If we're talking py3k I'd chuck "global" as a
> keyword though and replace it with something like "outer".
I must say that I don't like "outer" any more than I like "global." The
problem is that in both cases we are selecting the *inner*most definition
that isn't in the current scope.
More information about the Python-Dev
mailing list