class A:
def __init__(self):
print("Reporting from A")
def feature1(self):
return "feature1 from A working!"
class B(A):
def __init__(self):
print("Reporting from B")
def feature2(self):
return "feature2 from B working!"
class C(A,B): # multiple inheritance
def __init__(self):
super().__init__()
print("Reporting from C")
def feature3(self):
return "feature3 from C working!"
c = C()
错误消息:
class C(A,B): # multiple inheritance
TypeError: Cannot create a consistent method resolution
order (MRO) for bases A, B
但是当我将继承顺序从(A,B)
更改为(B,A)
时,它可以正常工作。**
结果,对于类似问题已经有了很好的解释:
TypeError: Cannot create a consistent method resolution order (MRO)