我试图继承一个超类属性的超类的属性,但他们没有被正确初始化:子类Python类继承
class Thing(object):
def __init__(self):
self.attribute1 = "attribute1"
class OtherThing(Thing):
def __init__(self):
super(Thing, self).__init__()
print self.attribute1
这将引发一个错误,因为ATTRIBUTE1不是一个属性OtherThing,即使Thing.attribute1存在。我认为这是继承和扩展超类的正确方法。难道我做错了什么?我不想创建一个Thing的实例并使用它的属性,为了简单起见,我需要它来继承它。
你想'超(OtherThing,个体经营).__的init __()' –