这显然是某种范围或导入问题,但我无法弄清楚。就像是:
classes.py
class Thing(object):
@property
def global_test(self):
return the_global
进而...
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
任何帮助都会很棒!