是否可以继承父母共有的多个阶层?
class A:
def __init__(self, a1, a2= a2 ):
self.a1=a1
self.a2=a2
def report(self):
print( here are my attrs: , self.a1, self.a2)
class B(A):
def __init__(self, b, *args, **kwargs):
self.b=b
A.__init__(self, *args, **kwargs)
class C(A):
def __init__(self, *args, c= c , **kwargs):
self.c=c
A.__init__(self, *args, **kwargs)
class D(B, C):
def __init__(self, *args, d= d , **kwargs):
self.d=d
super().__init__(self, *args, **kwargs)
If I try the above example I get:
TypeError: __init__() got multiple values for argument
之所以出现这一问题,是因为:*args
和**kwargs
在super(<>
>正在解决婚姻和家庭关系法时相互重复。
For context, I am trying to create a class that inherits methods and attributes from two other classes that share a parent.
If this is possible, how do you reconcile the different classes __init__
constructor?