【发布时间】:2020-03-20 20:29:56
【问题描述】:
假设我们定义了两个类:
class A():
def __init__(self):
self.a = 0
class B():
def __init__(self):
self.b = 0
现在,我们要定义第三个类C,它继承自A 和B:
class C(A, B):
def __init__(self):
A.__init__(self) # how to do this using super()
B.__init__(self) # how to do this using super()
【问题讨论】:
-
FWIW,我在my answer here 中间接回答了这个问题。 (答案是
super().__init__(),后跟super(A, self).__init__()。) -
这篇文章能回答你的问题吗? super multiple inheritance
-
另外请参阅 rhettinger 的 super considered super。他从他自己对该问题的回答中链接到该问题。
-
在提问之前,您是否尝试过在任何地方寻找答案? stackoverflow.com/a/27134600/4744341
标签: python python-3.x multiple-inheritance super