I have these 4 modules
globals.py
globvara = "a"
mod1.py
from globals import *
print globvara
output:
a
mod2.py
from mod1 import *
def changegv(newval1):
#global globvara
globvara = newval1
def usechangegv(newval2):
changegv(newval2)
and mod3.py
from mod2 import *
usechangegv("b")
print globvara
output:
a
a
I am wondering why the global var does not change in module 2. I am missing something in global variables. Even if I uncomment the global globvara line I get the same result. Where is the error?
globvarain each module, not just access it, and because he's not asking how to "work around" this problem, just asking what's happening).globvara = newval1will create a new local even if there's a global of the same name, unless you uncomment thatglobalstatement. But even with that statement, it will create a new (module-)global even if there's a builtin of the same name, and there is nobuiltinstatement to override that.