This is clearly a scope or import issue of some kind, but I can’t figure it out. Something like:
classes.py
class Thing(object):
@property
def global_test(self):
return the_global
And then…
test.py
from classes import Thing
global the_global
the_global = 'foobar'
t = Thing()
t.global_test
🙁
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "classes.py", line 4, in global_test
return the_global
NameError: global name 'the_global' is not defined
Any help would be great!
“global” in Python is a variable accessible in top level within module.
This message:
raised within
classes.pymeans you do not have a global namedthe_globalwithin yourclasses.pyfile.Python modules do not share global variables. (well, not in the way you want them to share)