variable scoping across imports?
Roy Mathew
roymath at yahoo.com
Sat Dec 1 11:26:53 EST 2001
Dear Pythoneers,
I have what seems to be a vexing problem.
In its simplest form, here are 2 files
# ------ file x.py ------------------------------------------------
z0 = None
import y
def set():
global z0
z0 = 33
if __name__=='__main__':
y.show()
set()
y.show()
# ------ file y.py ------------------------------------------------
import x
def show():
print x.z0
# -----------------------------------------------------------------
Now, I would expect that running "python x.py" would produce
None
33
but instead, it produces
None
None
I have read the rules on variable scoping pretty carefully, I think.
Are the circular imports confusing python. (BTW, I am using
"ActivePython 2.1, build 210 ActiveState").
What am I missing?
Thanks,
Roy.
More information about the Python-list
mailing list