A consistent Method Resolution Order couldn't be created (MRO error)
本问题已经有最佳答案,请猛点这里访问。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | class Base(object): def __init__(self): print ("Base") class childA(Base): def __init__(self): print ('Child A') Base.__init__(self) class childB(Base,childA): def __init__(self): print ('Child B') super(childB, self).__init__() b=childB() |
继承将按childb、base、childa、base进行,应用mro后,它将变为childb、childa、base。但它抛出了MRO错误。为什么?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | class Base(object): def __init__(self): print ("Base") class childA(Base): def __init__(self): print ('Child A') Base.__init__(self) class childB(childA): def __init__(self): print ('Child B') super(childB, self).__init__() b=childB() |