가능한 중복 :
Can Super deal with multiple inheritance?Super를 사용하여 여러 상위 클래스에 대해 init을 호출합니까?
파이썬 상속? 클래스 구조 (아래)가 있으며 하위 클래스에서 두 부모의 __init__
을 호출하기를 원합니다. 이것은 '슈퍼'방식으로 할 수 있습니까 아니면 그냥 끔찍한 생각입니까?
class Parent1(object):
def __init__(self):
self.var1 = 1
class Parent2(object):
def _init__(self):
self.var2 = 2
class Child(Parent1, Parent2):
def __init__(self):
## call __init__ of Parent1
## call __init__ of Parent2
## super(Child, self).__init__()
다른 많은 질문과 답변을 읽었을 때 'super()'가 "MRO 체인의 다음 기능"을 호출하는 방법을 지적한 사람은 귀하뿐입니다. 참으로 간단하면서도 매우 중요한 성명서. – MikeyE