我正在尝试从超类继承属性,但它们未正确初始化:
class Thing(object):
def __init__(self):
self.attribute1 = "attribute1"
class OtherThing(Thing):
def __init__(self):
super(Thing, self).__init__()
print self.attribute1
这会引发错误,因为即使Thing.attribute1存在,attribute1也不是OtherThing的属性。我认为这是继承和扩展超类的正确方法。难道我做错了什么?我不想创建Thing的实例并使用其属性,为了简单起见,我需要它来继承它。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句