what is happening here?
dan miller (moderator, s.p.d)
danbmil at cmu.edu
Tue Apr 6 18:29:00 EDT 2004
trying to figure out scoping of 'globals' in modules. So I have test.py:
glob = 1
def setglob(v):
global glob
glob = v
def getglob():
return glob
and I do this:
>>> from test import *
>>> glob
1
>>> getglob()
1
>>> glob=2
>>> glob
2
>>> getglob()
1
>>> setglob(3)
>>> getglob()
3
>>> glob
2
Seems to me like the first time I invoke glob, it creates a new global
in my namespace, and initializes it to the value of the glob in test.py.
Seems counterintuitive!
More information about the Python-list
mailing list