I cannot write into a global variable in the following program. Can someone please give me a solution to this? Note that my var
variable must be in other file than Mod2.py
and Mod3.py
In Mod1.py
var = 5
In Mod2.py
from Mod1 import *
def foo(newValue):
global var
print('foo: %d' % var)
var = newValue
print('before: %d' % var)
foo(2)
print('after: %d' % var)
In Mod3.py
from Mod2 import *
foo(3)
print('var: %d' % var)
The result when running Mod3.py
is
before: 5
foo: 5
after: 2
foo: 2
var: 2
But I expect it to be
before: 5
foo: 5
after: 2
foo: 2
var: 3
I do not want a solution using import Modx.py