我有一個繼承的類並覆蓋了一個方法,它也從基類繼承。但事情是,中間方法創建一個異常,我想通過調用第一個聲明的方法繞過。有沒有辦法指定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