我希望从两个不同的类继承它们的__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__
。在
我相信你可以像下面这样做
相关问题 更多 >
编程相关推荐