我想从类外部创建一个静态类变量,或者想要访问从外部类声明的变量。
class test(object):
in_class = var
class test():
global var
var = 20
j = test()
print j.in_class
这给出了
Traceback (most recent call last):
File "class_test.py", line 1, in <module>
class test(object):
File "class_test.py", line 2, in test
in_class = var
NameError: name 'var' is not defined