我有一个继承的类并覆盖了一个方法,它也从基类继承。但事情是,中间方法创建一个异常,我想通过调用第一个声明的方法绕过。有没有办法指定mro忽略第二个电话?Python超级绕过MRO
一个例子可以是:
class Base(object):
def __init__(self):
res = "Want this"
print res
class BaseA(Base):
def __init__(self):
res = super(BaseA, self).__init__()
res = "Not this"
print res
class BaseB(BaseA):
def __init__(self):
res = super(BaseB, self).__init()
#At this poing res is "Not this"
#The desire is that it would be "Want this"
print res
非常感谢
PD: 喜欢的东西类BaseB(基地BaseA)可以工作?
“类BaseB(Base,BaseA)可以工作吗?”。不,它会引发异常:调用元类时出现TypeError:错误 无法为基Base,BaseA'创建一致的方法解析 order(MRO)。在这种情况下,你必须直接调用特定的父类... – Bakuriu