Lexical Scope

Paul Clinch pclinch at internet-glue.co.uk
Thu Oct 30 13:45:57 EST 2003


>From the language lawyers section of python doc.s :-

"If a name is assigned to anywhere in a code block (even in
unreachable code), and is not mentioned in a global statement in that
code block, then it refers to a local name throughout that code
block."

Try:-

def run():
  a = 1
  def run2(b):
    global a
    print a
    a = b
  run2(2)
  print a
run()




More information about the Python-list mailing list