[python]: confused by super ()

Possible duplicate:
Understanding Python super ()

Class B subclasses of class A , so in B __init__ we should call A __init__ as follows:

 class B(A): def __init__(self): A.__init__(self) 

But with super() I saw something like this:

 class B(A): def __init__(self): super(B, self).__init__() #or super().__init__() 

My questions:

  • Why not super(B, self).__init__(self) ? Just because the return proxy object object is bound?

  • If I omit the second argument to super and the returned proxy object is unbound, should I write super(B).__init__(self) ?

+4
source share
1 answer

super() returns an instance of the base class, so self implicitly passed to __init__() , as in any other method call.

As for your second question, this is correct. Calling super() without an instance, as the second argument returns a reference to the class itself, and not an instance built from your subclass instance.

+5
source

All Articles