Here's my simple script, called aScript.py:
a = 0
a = 1
Then in the python interpreter in do the following 4 commands:
>>>from aScript import *
Why does it print:
Instead of (which is what I expected btw):
I'm using python 2.6.
...Why does it print 0 0?
Best How To :
global variables are only global in their own module, therefore
load() only modifies the
a variable inside
aScript, not the imported
When you do
from aScript import *, python iterates over
aScript's public variables and creates a copy of each in the current module, that is, it creates
__main__.a equal to
aScript.a. Now you call
load, which is actually
aScript.load which modifies its own
aScript.a), but since it has no idea about
__main__.a, the latter is left intact.