我希望能夠從兩個不同的輸入到其__init__
方法中的不同類繼承。我如何正確地從它們繼承?如何從具有不同__init__輸入的多個類繼承?
下面是什麼,我試圖完成一個簡單的例子:
class a:
def __init__(self):
print("Hello")
class b(a):
def __init__(self):
super().__init__()
print("World")
class c:
def __init__(self, text):
print(text)
class d(a, c):
def __init__(self):
super().__init__('Kronos') # <-- This breaks (and understandably so)
雖然類似多重繼承的其他許多問題(即How does Python's super() work with multiple inheritance?),我正在尋找如何繼承從具有不同輸入的多個類到它們的__init__
。
的可能的複製[如何Python的超()與多重繼承工作?](http://stackoverflow.com/questions/3277367/how-does -pythons-super-work-with-multiple-inheritance) – electrometro
考慮在你的'__init__'方法中加入一個'* args,** kwargs' –
你可以試試我的編輯 – DreadfulWeather