I came across a strange issue in Python when using global variables.
I have two modules(files):mod1.py and mod2.py
mod1 tries to modify the global variable var defined in mod2. But the var in mod2 and var in mod seems to be two different things. Thus, the result shows that such modification does not work.
Here is the code:
#code for mod2.py
global var
var = 1
def fun_of_mod2():
print var
#code for mod1.py
from mod2 import var,fun_of_mod2
global var #commenting out this line yields the same result
var = 2 #I want to modify the value of var defined in mod2
fun_of_mod2() #but it prints: 1 instead of 2. Modification failed :-(
Any hint on why this happens? And how can I modify the value of val defined in mod2 in mod1?
Thanks