由于原始代码太长,下面将简化此问题,
class FirstClass(object):
a = 1
b = a+2
def Outcome_1(self):
c = a+b
print(c)
def Outcome_2(self):
c = b-a
print(c)
d = FirstClass()
d.Outcome_1()
输出结果为:NameError: name 'a' is not defined
。那么我们如何通过类方法访问静态类变量,或者有更好的方法呢?