我试图从派生类中的基类访问一个类变量,得到一个noAttributeError
class Parent(object):
variable = 'foo'
class Child(Parent):
def do_something(self):
local = self.variable
我试着用它作为Parent.variable
,但也没用。我也犯了同样的错误
AttributeError: 'Child' object has no attribute 'Child variable'
我如何解决这个问题
Tags:
我不知道你做错了什么。但是,下面的代码假设您有一个初始化方法。在
输出:
^{pr2}$下面显示的代码应该同时适用于Python 2&3:
相关问题 更多 >
编程相关推荐