programing

'super'는 Python에서 무엇을 합니까? - super()의 차이점.__init__() 및 명시적 슈퍼클래스 __init_()

luckcodes 2022. 10. 8. 09:57

'super'는 Python에서 무엇을 합니까? - super()의 차이점.__init__() 및 명시적 슈퍼클래스 __init_()

차이점은 무엇입니까?

class Child(SomeBaseClass):
    def __init__(self):
        super(Child, self).__init__()

또, 다음과 같이 합니다.

class Child(SomeBaseClass):
    def __init__(self):
        SomeBaseClass.__init__(self)

적이 있다super한 가지 상속만 있는 수업에서 꽤 많이 사용되고 있습니다.왜 다중 상속에서 사용하는지는 알 수 있지만, 이런 상황에서 사용하는 장점이 무엇인지 알 수 없습니다.

뭐가 다른데?

SomeBaseClass.__init__(self) 

를 호출하는 SomeBaseClass의 »__init__ .하는 동안에

super().__init__()

「」를 .__init__ 나오는 SomeBaseClassMRO(Method Resolution Order)는 MRO(Method Resolution Order)입니다.

인스턴스가 이 자식 클래스의 하위 클래스인 경우 MRO에서 다음에 오는 다른 부모가 있을 수 있습니다.

알기 쉽게 설명

당신이 수업을 쓸 때, 당신은 다른 수업들이 그것을 사용할 수 있기를 원한다. super()다른 클래스가 당신이 쓰고 있는 클래스를 더 쉽게 사용할 수 있도록 합니다.

Bob Martin이 말했듯이, 좋은 아키텍처는 의사결정을 가능한 한 오래 미룰 수 있게 해줍니다.

super()그런 종류의 아키텍처를 가능하게 합니다.

작성한 클래스를 다른 클래스가 서브클래스 할 경우 다른 클래스에서 상속될 수도 있습니다. 그 은 '아예'를 수 .__init__ 뒤에 것__init__메서드 해결을 위한 클래스의 순서를 기반으로 합니다.

super작성 중인 클래스의 부모(예시와 같이)를 하드 코드화할 수 있습니다., 다음 을 ''라고 부르지 입니다.__init__MRO를 사용하다

개인적인 용도로 자신만의 코드를 작성하는 경우 이 구분은 신경 쓰지 않을 수 있습니다.하는 것을 하세요.super코드 사용자에게 보다 유연한 기능을 제공합니다.

Python 2 대 3

이것은 Python 2와 3에서 동작합니다.

super(Child, self).__init__()

이것은 Python 3에서만 동작합니다.

super().__init__()

첫메서드로 없이 합니다(보통 " " " " " " " " " " " " 입니다.self 메서드 또는 " method"의 경우cls메서드 - 도 있음) 및 클래스 검색:Child 변수free'('free'('free')라는 __class__을 참조해 주십시오.)

이 있는 했습니다.super는 크게되지 않기 의 작업, Python 2를 호출하는 에 대해 super의론 없이.

전송 호환성을 가진 간접

게게당 당신 ?엇? ???단일 상속의 경우, 질문의 예는 정적 분석 관점에서 실질적으로 동일합니다. ,를 super는 순방향 호환성을 가진 간접 레이어를 제공합니다.

노련한 개발자에게는 전방 호환성이 매우 중요합니다.코드를 변경할 때 최소한의 변경으로 계속 작동해야 합니다.리비전 이력을 확인할 때는 언제 무엇이 변경되었는지 정확하게 확인해야 합니다.

첫 번째 상속은 단일 상속으로 시작할 수 있지만 다른 기본 클래스를 추가하는 경우 기본 클래스로만 행을 변경하면 됩니다. 상속된 클래스에서 기본이 변경되면(mixin이 추가되었다고 가정하면) 이 클래스는 변경되지 않습니다.

를 Python 2로 .super올바른 메서드 인수는 조금 혼란스러울 수 있으므로 Python 3만의 메서드 호출을 권장합니다.

하고 있는 있는 super1개의 상속으로 올바르게 디버깅을 실행할 수 있기 때문에 앞으로 디버깅이 어려워지지 않습니다.

의존 관계 주입

다른 사람이 당신의 코드를 사용하여 부모에게 메서드 해결 방법을 주입할 수 있습니다.

class SomeBaseClass(object):
    def __init__(self):
        print('SomeBaseClass.__init__(self) called')
    
class UnsuperChild(SomeBaseClass):
    def __init__(self):
        print('UnsuperChild.__init__(self) called')
        SomeBaseClass.__init__(self)
    
class SuperChild(SomeBaseClass):
    def __init__(self):
        print('SuperChild.__init__(self) called')
        super().__init__()

오브젝트에 다른 클래스를 추가하고 Foo와 Bar 사이에 클래스를 삽입하는 경우(테스트 또는 기타 이유로):

class InjectMe(SomeBaseClass):
    def __init__(self):
        print('InjectMe.__init__(self) called')
        super().__init__()

class UnsuperInjector(UnsuperChild, InjectMe): pass

class SuperInjector(SuperChild, InjectMe): pass

사용 중인 자녀가 자신의 메서드 뒤에 호출할 메서드를 하드 코딩했기 때문에 비슈퍼 자식 사용 시 종속성 주입에 실패합니다.

>>> o = UnsuperInjector()
UnsuperChild.__init__(self) called
SomeBaseClass.__init__(self) called

「」, 「」를 클래스.super할 수 .

>>> o2 = SuperInjector()
SuperChild.__init__(self) called
InjectMe.__init__(self) called
SomeBaseClass.__init__(self) called

코멘트의 수신처 지정

이게 대체 왜 유용한 거죠?

Python은 C3 선형화 알고리즘을 통해 복잡한 상속 트리를 선형화하여 MRO(Method Resolution Order)를 만듭니다.

우리는 그 순서대로 방법을 찾아보고 싶다.

되어 있는 으로, 부모에게 없는 super 될 것

  1. 인스턴스 유형에서 mro를 가져옵니다.
  2. 방법을 정의하는 유형을 찾다
  3. 그 방법으로 다음 유형을 찾아내다
  4. 그 메서드를 바인드하여 예상되는 인수를 사용하여 호출한다.

UnsuperChild 할 수 .InjectMe'라는 안 요?super가 뭘 ?" 가가뭘 쳤??

UnsuperChild에 액세스 할 수 없다.InjectMe바로 그입니다.UnsuperInjector 할 수 .InjectMe 그 클래스가 에서 그 할 수 UnsuperChild.

두 자녀 클래스는 MRO에서 다음에 오는 동일한 이름으로 메서드를 호출하려고 합니다.이러한 클래스는 작성 시 인식하지 못한 다른 클래스일 수 있습니다.

★★★★★★★★★★★가 없는 것super부모 메서드의 하드캐스팅 - 따라서 메서드의 동작이 제한되고 서브클래스는 콜체인에 기능을 삽입할 수 없습니다.

있는 사람 super이치노메서드의 콜체인을 대행 수신하여 기능을 삽입할 수 있습니다.

이 기능은 필요하지 않을 수 있지만 코드의 서브클래서가 필요할 수 있습니다.

결론

「」를 사용합니다.super부모 클래스를 하드캐스팅하지 않고 참조할 수 있습니다.

다음 줄에 있는 부모 클래스를 참조하는 것이지, 특히 자녀가 상속하는 부모 클래스를 참조하는 것은 아닙니다.

「」를 .super코드 사용자에게 불필요한 제약을 가할 수 있습니다.

★★★의 super()이치노대부분 기본 클래스의 이름을 부모 메서드를 사용하는 모든 메서드에 하드 코드화할 필요는 없습니다.

라는 게 없으면 거의 super()여기에는 믹스인, 인터페이스, 추상 클래스 등 일반적인 관용어가 포함됩니다.이것은 나중에 확장되는 코드로 확장됩니다.만약 누군가가 나중에 그 수업을 쓰고 싶어 한다면Child그리고 믹스인은 그들의 코드가 제대로 작동하지 않을 것이다.

나는 조금 놀았었다.super()발신 순서를 변경할 수 있다는 것을 인식하고 있었습니다.

예를 들어 다음 계층 구조가 있습니다.

    A
   / \
  B   C
   \ /
    D

경우 D의 MRO는 다음과 같습니다(Python 3의 경우에만).

In [26]: D.__mro__
Out[26]: (__main__.D, __main__.B, __main__.C, __main__.A, object)

이 수업을 하다, 하다, 하다, 이렇게 수업을 볼까요?super()★★★★★★★★★★★★★★★★★★★★★★★★★★

In [23]: class A(object): #  or with Python 3 can define class A:
...:     def __init__(self):
...:         print("I'm from A")
...:  
...: class B(A):
...:      def __init__(self):
...:          print("I'm from B")
...:          super().__init__()
...:   
...: class C(A):
...:      def __init__(self):
...:          print("I'm from C")
...:          super().__init__()
...:  
...: class D(B, C):
...:      def __init__(self):
...:          print("I'm from D")
...:          super().__init__()
...: d = D()
...:
I'm from D
I'm from B
I'm from C
I'm from A

    A
   / ⇖
  B ⇒ C
   ⇖ /
    D

같은 로 MRO를 를 알 수 .만만, 화전,,super()in메메 in in in in in in in in in in in in in.

In [21]: class A(object):  # or class A:
...:     def __init__(self):
...:         print("I'm from A")
...:  
...: class B(A):
...:      def __init__(self):
...:          super().__init__()  # or super(B, self).__init_()
...:          print("I'm from B")
...:   
...: class C(A):
...:      def __init__(self):
...:          super().__init__()
...:          print("I'm from C")
...:  
...: class D(B, C):
...:      def __init__(self):
...:          super().__init__()
...:          print("I'm from D")
...: d = D()
...: 
I'm from A
I'm from C
I'm from B
I'm from D

MRO 태플 순서가 바뀌었습니다.

    A
   / ⇘
  B ⇐ C
   ⇘ /
    D 

자세한 내용은 다음 답변을 참조하십시오.

  1. 슈퍼(대형 계층)를 사용한 C3 선형화 예시
  2. 구식 클래스와 신식 클래스 간의 중요한 동작 변화
  3. 새로운 스타일의 수업 내막

이 모든 것은 기본 클래스가 새로운 스타일의 클래스라고 가정하지 않나요?

class A:
    def __init__(self):
        print("A.__init__()")

class B(A):
    def __init__(self):
        print("B.__init__()")
        super(B, self).__init__()

파이썬 2 ★★★★★★★★★★★★★★★★★★★★★★★★★★★★★」class A새로운 스타일의 제품이어야 합니다.class A(object)

" " 를 할 super()클래스 메서드, 인스턴스 메서드 또는 스태틱메서드의 부모 버전으로 해결하려면 현재 클래스를 첫 번째 인수로 전달하고 해결하려는 부모 범위를 나타내며 두 번째 인수로 해당 범위를 적용하려는 개체를 나타냅니다.

계층을 A,B , , , , 입니다.C서 각 는 그 뒤에 이고, 각 클래스는 그 뒤에 오는 클래스의 부모입니다.a,b , , , , 입니다.c각각의 예.

super(B, b) 
# resolves to the scope of B's parent i.e. A 
# and applies that scope to b, as if b was an instance of A

super(C, c) 
# resolves to the scope of C's parent i.e. B
# and applies that scope to c

super(B, c) 
# resolves to the scope of B's parent i.e. A 
# and applies that scope to c

「」를 사용합니다.super

: : 용 e 。super()__new__()

class A(object):
    def __new__(cls, *a, **kw):
        # ...
        # whatever you want to specialize or override here
        # ...

        return super(A, cls).__new__(cls, *a, **kw)

설명:

- - 상상인 1 1 1 1 1 1 1 1 1 1 。__new__()호출 클래스에 대한 참조를 첫 번째 매개 변수로 받아들이기 위해, 이것은 클래스 메서드가 아니라 정적 메서드로 Python에 구현됩니다.즉, 호출할 때 클래스에 대한 참조가 첫 번째 인수로 명시적으로 전달되어야 합니다.__new__()★★★★

# if you defined this
class A(object):
    def __new__(cls):
        pass

# calling this would raise a TypeError due to the missing argument
A.__new__()

# whereas this would be fine
A.__new__(A)

시 시super() 자녀 합니다.A첫 번째해 주는데, 이 에는 '아, 아, 아, 아, 아, 아, 아, 아, 아, 아, 아, 아, 아, 아, 아, 아, 아, 아, 아, 아, 아, 아, 아, 아, 아, 아, 아, 아, 아, 아, 아, 아, 아, 아, 아, 아, 아, 아, 아, 아, 아, 아, 아, 아, 아, 아, 아, 아, 아.A.__new__(cls)을 사용하다대부분의 경우 이는 자녀 클래스에 대한 참조이기도 합니다.예를 들어 여러 세대 상속의 경우 그렇지 않은 경우가 있습니다.

super(A, cls)

- 으로는 3 - 「 」이기 입니다.__new__()메서드입니다.super(A, cls).__new__객체에 참조를 한 모든 .이 static instest는 static " " " 입니다.cls.

super(A, cls).__new__(cls, *a, **kw)

- 을 4 없이 - 같은 일을 . - 네, 네, 네, 네, 네, 네, 네, 네, 네, 네, 네, 네, 네, 네.super

class A(object):
    def __new__(cls, *a, **kw):
        # ...
        # whatever you want to specialize or override here
        # ...

        return object.__new__(cls, *a, **kw)

「」를 사용합니다.super

: : 용 e 。super()에서)__init__()

class A(object): 
    def __init__(self, *a, **kw):
        # ...
        # you make some changes here
        # ...

        super(A, self).__init__(*a, **kw)

설명:

- 1 -__init__는 인스턴스 메서드입니다.즉, 첫 번째 인수로 인스턴스에 대한 참조를 사용합니다.인스턴스에서 직접 호출하면 참조가 암묵적으로 전달됩니다.즉, 참조를 지정할 필요가 없습니다.

# you try calling `__init__()` from the class without specifying an instance
# and a TypeError is raised due to the expected but missing reference
A.__init__() # TypeError ...

# you create an instance
a = A()

# you call `__init__()` from that instance and it works
a.__init__()

# you can also call `__init__()` with the class and explicitly pass the instance 
A.__init__(a)

시 시super()의 범위 내에서__init__()우리는 자녀 클래스를 첫 번째 인수로 전달하고 관심 대상을 두 번째 인수로 전달하며, 이는 일반적으로 자녀 클래스의 인스턴스에 대한 참조입니다.

super(A, self)

- 콜 3 - 콜super(A, self)는 범위를 합니다.self마치 부모 클래스의 인스턴스가 된 것처럼요. 프록시를 '프록시'라고 부르겠습니다s .부터__init__()입니다.s.__init__(...) of of of of of of of of of 의 참조를 암묵적으로 self의 첫 __init__().

- 4를 사용하지 않고 한 작업을 합니다.super부모 .__init__().

class A(object): 
    def __init__(self, *a, **kw):
        # ...
        # you make some changes here
        # ...

        object.__init__(self, *a, **kw)

「」를 사용합니다.super method로 했습니다.

class A(object):
    @classmethod
    def alternate_constructor(cls, *a, **kw):
        print "A.alternate_constructor called"
        return cls(*a, **kw)

class B(A):
    @classmethod
    def alternate_constructor(cls, *a, **kw):
        # ...
        # whatever you want to specialize or override here
        # ...

        print "B.alternate_constructor called"
        return super(B, cls).alternate_constructor(*a, **kw)

설명:

1- 클래스 메서드는 클래스에서 직접 호출할 수 있으며 첫 번째 매개 변수로 클래스에 대한 참조를 취합니다.

# calling directly from the class is fine,
# a reference to the class is passed implicitly
a = A.alternate_constructor()
b = B.alternate_constructor()

시 시super()클래스 메서드 내에서 현재 자녀 클래스를 부모 버전으로 해결하려는 부모 범위를 나타내는 첫 번째 인수로 전달하고 해당 범위를 적용할 개체를 나타내는 두 번째 인수로 전달합니다. 서브클래스 중 하나f 또는 그 하나.

super(B, cls_or_subcls)

- 콜 3 - 콜super(B, cls)A cls .부터alternate_constructor() classmethod 입니다.super(B, cls).alternate_constructor(...) of of of of of of of of of 의 참조를 암묵적으로 cls의 첫 A의 ' 'alternate_constructor()

super(B, cls).alternate_constructor()

4 - 사용하지 않고 동일한 작업을 수행할 수 있습니다.super()의 언바인드 버전에 대한 참조가 필요합니다.A.alternate_constructor()(예: 함 ( 、 ( ( ( ( ( ( ( ().단순히 이렇게 하는 것은 효과가 없습니다.

class B(A):
    @classmethod
    def alternate_constructor(cls, *a, **kw):
        # ...
        # whatever you want to specialize or override here
        # ...

        print "B.alternate_constructor called"
        return A.alternate_constructor(cls, *a, **kw)

의 경우는, 「이렇게 하면 안 된다」라고 되어 있기 때문에, 상기의 는 안 .왜냐하면A.alternate_constructor()인 참조를 합니다.A그그cls여기서 통과되는 것이 두 번째 논쟁이 될 것입니다.

class B(A):
    @classmethod
    def alternate_constructor(cls, *a, **kw):
        # ...
        # whatever you want to specialize or override here
        # ...

        print "B.alternate_constructor called"
        # first we get a reference to the unbound 
        # `A.alternate_constructor` function 
        unbound_func = A.alternate_constructor.im_func
        # now we call it and pass our own `cls` as its first argument
        return unbound_func(cls, *a, **kw)

요약하면 Super()

  • 모든 Python 인스턴스에는 이 인스턴스를 만든 클래스가 있습니다.
  • Python의 모든 클래스에는 상위 클래스의 체인이 있습니다.
  • super()를 사용하는 메서드는 체인의 다음 상위 항목에 인스턴스 클래스의 작업을 위임합니다.

이 작은 예에서는 모든 대상 사례를 다룹니다.

class A:
    def m(self):
        print('A')

class B(A):
    def m(self):
        print('B start')
        super().m()
        print('B end')
        
class C(A):
    def m(self):
        print('C start')
        super().m()
        print('C end')

class D(B, C):
    def m(self):
        print('D start')
        super().m()
        print('D end')

콜의 정확한 순서는 메서드가 호출된 인스턴스에 따라 결정됩니다.

>>> a = A()
>>> b = B()
>>> c = C()
>>> d = D()

를 들어 a에는 슈퍼콜이 없습니다.

>>> a.m()
A

를 들어 b의 상위 체인은B -> A -> object:

>>> type(b).__mro__   
(<class '__main__.B'>, <class '__main__.A'>, <class 'object'>)

>>> b.m()
B start
A
B end

를 들어 c의 상위 체인은 다음과 같습니다.C -> A -> object:

>>> type(c).__mro__   
(<class '__main__.C'>, <class '__main__.A'>, <class 'object'>)

>>> b.m()
C start
A
C end

를 들어 d는 상위 체인이 더 흥미롭다.D -> B -> C -> A -> object(mro는 메서드 해결 순서를 나타냅니다).

>>> type(d).__mro__
(<class '__main__.D'>, <class '__main__.B'>, <class '__main__.C'>, <class '__main__.A'>, <class 'object'>)

>>> d.m()
D start
B start
C start
A
C end
B end
D end

많은 정보

"파이썬에서 슈퍼는 무엇을 하는가?"라는 질문에 답한 후, 다음 질문은 그것을 어떻게 효과적으로 사용할 것인가이다.이 단계별 튜토리얼 또는 45분짜리 비디오를 참조하십시오.

훌륭한 답변이 많지만 시각 학습자의 경우:우선 슈퍼에 대한 주장을 가지고 탐색하고 다음으로 슈퍼에 대한 주장을 배제합니다.슈퍼 상속 트리 예시

해 보세요.jack에서 Jack그림에서 녹색으로 표시된 상속 체인을 가지고 있습니다.★★★★

super(Jack, jack).method(...)

는 MRO(Method Resolution Order)의 Order합니다.jack 트리)에서 검색을 합니다.Jack왜부 클클 클래 공?? ???를 들어 jack을 사용법을 사용법

첫 인수가 super의 .self, 두 번째 는 '먹다'입니다selfPython3를 사용하다

'안'는 을 안 쓴다고 해 주세요.Jack이 의 메서드JackJenJen.

에 한 을 한 1 、 깊 1 ( not 1 ) 。를를,, 음음음음음음음음Adam ★★★★★★★★★★★★★★★★★」Sue다방법이 , 그이 있다.Sue먼저 발견됩니다.

ifCain ★★★★★★★★★★★★★★★★★」Sue 다 방법을 가지고 .Cain의 메서드가 먼저 호출됩니다.이것은, 다음의 코드에 대응합니다.

Class Jen(Cain, Sue):

MRO는 왼쪽에서 오른쪽으로 되어 있습니다.

다중 상속의 경우 일반적으로 첫 번째 상속뿐만 아니라 두 개의 상위 이니셜라이저를 호출해야 합니다.super()는 항상 기본 클래스를 사용하는 대신 MRO(Method Resolution Order)의 다음 클래스를 찾아 현재 개체를 해당 클래스의 인스턴스로 반환합니다.예를 들어 다음과 같습니다.

class Base(object):
    def __init__(self):
        print("initializing Base")

class ChildA(Base):
    def __init__(self):
        print("initializing ChildA")
        Base.__init__(self)

class ChildB(Base):
    def __init__(self):
        print("initializing ChildB")
        super().__init__()

class Grandchild(ChildA, ChildB):
    def __init__(self):
        print("initializing Grandchild")
        super().__init__()
        
Grandchild()

을 낳다

initializing Grandchild
initializing ChildA
initializing Base

<고객명>의 치환Base.__init__(self)super().__init__()를 초래하다

initializing Grandchild
initializing ChildA
initializing ChildB
initializing Base

원하는 대로

좋은 이 몇 , .super()계층 내 다른 클래스의 시그니처가 다른 경우... 특특의의 __init__

할 수 super()답변 super()를 읽고 공동 메서드의 시그니처를 변경하는 것이 좋습니다.

이 시나리오에 대한 해결책은 다음과 같습니다.

  1. 내 .SuperObject:
  2. 가 다른 수 , 한 인수를 항상 .**kwargs.
class SuperObject:        
    def __init__(self, **kwargs):
        print('SuperObject')
        mro = type(self).__mro__
        assert mro[-1] is object
        if mro[-2] is not SuperObject:
            raise TypeError(
                'all top-level classes in this hierarchy must inherit from SuperObject',
                'the last class in the MRO should be SuperObject',
                f'mro={[cls.__name__ for cls in mro]}'
            )

        # super().__init__ is guaranteed to be object.__init__        
        init = super().__init__
        init()

사용 예:

class A(SuperObject):
    def __init__(self, **kwargs):
        print("A")
        super(A, self).__init__(**kwargs)

class B(SuperObject):
    def __init__(self, **kwargs):
        print("B")
        super(B, self).__init__(**kwargs)

class C(A):
    def __init__(self, age, **kwargs):
        print("C",f"age={age}")
        super(C, self).__init__(age=age, **kwargs)

class D(B):
    def __init__(self, name, **kwargs):
        print("D", f"name={name}")
        super(D, self).__init__(name=name, **kwargs)

class E(C,D):
    def __init__(self, name, age, *args, **kwargs):
        print( "E", f"name={name}", f"age={age}")
        super(E, self).__init__(name=name, age=age, *args, **kwargs)

E(name='python', age=28)

출력:

E name=python age=28
C age=28
A
D name=python
B
SuperObject

다음 코드를 고려합니다.

class X():
    def __init__(self):
        print("X")

class Y(X):
    def __init__(self):
        # X.__init__(self)
        super(Y, self).__init__()
        print("Y")

class P(X):
    def __init__(self):
        super(P, self).__init__()
        print("P")

class Q(Y, P):
    def __init__(self):
        super(Q, self).__init__()
        print("Q")

Q()

Y로로 합니다.X.__init__ , , , , , , , , , , , , , , , , , , , , 이 .

X
Y
Q

,, 을, 을, 용을 super(Y, self).__init__() , , , , , , , , , , , , , , , , , , , , 이 .

X
P
Y
Q

★★★★★★★★★★★★★★★★★.P ★★★★★★★★★★★★★★★★★」Q쓸 때 될 수 있습니다.X ★★★★★★★★★★★★★★★★★」Y으로는 무엇을 해야 하는지 알 없습니다.super(Child, self) 글을 쓸 .class Y(X)도 Y의 처럼 간단하다.Y(X)그래서 슈퍼가 더 나은 선택이 될 수 있는 거죠.

class Child(SomeBaseClass):
    def __init__(self):
        SomeBaseClass.__init__(self)

이것은 꽤 이해하기 쉽다.

class Child(SomeBaseClass):
    def __init__(self):
        super(Child, self).__init__()

그럼 요?super(Child,self)

하위 인스턴스를 만들 때 MRO(Method Resolution Order)는 상속을 기준으로 (Child, SomeBaseClass, object)의 순서가 됩니다.(SomeBaseClass에는 기본 오브젝트 이외의 상위 오브젝트가 없는 것으로 가정합니다.)

Child, self,super""의selfinstance)를 Child(차일드) 이 경우 이 오브젝트는 Child(인스턴스)를 합니다.「SomeBaseClass」를 선택합니다.SomeBaseClass basebase 。__init__SomeBaseClass 。바말 약약의 경우, 약약의 경우super(SomeBaseClass,self), 「」를 참조해 주세요superobject

상속의 클래스가 될 수 기본적으로는 'Da' MRO'입니다.superMRO에서 검색을 시작할 위치를 결정할 수 있습니다.

언급URL : https://stackoverflow.com/questions/222877/what-does-super-do-in-python-difference-between-super-init-and-expl