【发布时间】:2014-10-11 22:02:18
【问题描述】:
考虑以下代码:
class A(object):
def __init__(self):
pass
class B(object):
def __init__(self):
self.something = 'blue'
def get_something(self):
return self.something
class C(A,B):
def __init__(self):
super().__init__()
print(self.get_something())
然后做:
c = C()
结果如下:
AttributeError: 'C' object has no attribute 'something'
我想这是因为使用 super() 时没有调用 B 的构造函数。有没有办法使用 Python 3 实现正确的行为?
【问题讨论】:
标签: python oop inheritance python-3.x multiple-inheritance