Using variables across modules
Aaron Scott
aaron.hildebrandt at gmail.com
Wed Jul 23 15:06:02 EDT 2008
> Just wirte test code !
variables.py:
myvar = 5
print myvar
foo.py:
from variables import *
def PrintVar():
print myvar
bar.py:
from variables import *
from foo import *
print myvar
myvar = 2
print myvar
PrintVar()
"python bar.py" output:
5
5
2
5
... which is what I was expecting, but not what I want. Obviously,
each import is creating its own instance of the variable. What I need
is a way to change myvar from within "bar.py" so that PrintVar()
returns the new value, even though it's in a different module.
More information about the Python-list
mailing list