nested scopes

Darren New dnew at
Mon Feb 5 13:39:07 EST 2001

D-Man wrote:
> professor didn't know of any situations where it would be
> advantageous, and I couldn't contrive any either.  I was kind of
> surprised when I heard python described as "dynamically scoped"
> because its scoping was really quite natural for me.

That's because your prof doesn't know what "dynamic scoping" is.

def alpha():
  a = 5

def beta():
  a = 17

def gamma():
  print a


With dynamic scoping, this would print "5" then "17" then "5" again, as
"gamma" would basically walk up the run-time call stack looking for the most
recent "a" to print. (Note that "a" is supposed to be local everywhere, not
a global.) Obviously, this is *not* how Python works.  

Darren New / Senior MTS & Free Radical / Invisible Worlds Inc.
San Diego, CA, USA (PST).  Cryptokeys on demand.
                 Ignorance can be cured. Naivety cures itself.

More information about the Python-list mailing list