[Python-Dev] Re: Dynamic nested scopes

Jeremy Hylton jeremy@alum.mit.edu
Thu, 2 Nov 2000 12:57:09 -0500 (EST)


I don't think I buy your explanation that Python uses dynamic scope
for resolving globals.  As I understand the mechanism, the module
namespace and builtins namespace are those for the module in which the
function was defined.  If so, this is still static scope.

Here's a quick example that illustrates the difference:

module foo:
-----------------------
a = 12

def add(b):
    return a + b
-----------------------

module bar:
-----------------------
from foo import add

a = -1
print add(1)
-----------------------

If Python used static scope, "python bar.py" should print 13 (it
does).  If it used dynamic scope, I would expect the answer to be 0.

Jeremy