[Python-Dev] nested scopes. global: have I got it right?

Samuele Pedroni pedroni@inf.ethz.ch
Thu, 1 Mar 2001 01:57:45 +0100


Hi. Is the following true?

PEP227 states:
"""
If the global statement occurs within a block, all uses of the
name specified in the statement refer to the binding of that name
in the top-level namespace.
"""

but this is a bit ambiguous, because the global decl (I imagine for
backw-compatibility)
does not affect the code blocks of nested (func) definitions. So

x=7
def f():
  global x
  def g():
    exec "x=3"
    return x
  print g()

f()

prints 3, not 7.


PS: this improve backw-compatibility but the PEP is ambiguous or block concept
does
not imply nested definitions(?). This affects only special cases but it is
quite strange in presence
of nested scopes, having decl that do not extend to inner scopes.