Chain-calling parent initialisers in python [duplicate] Chain-calling parent initialisers in python [duplicate] python python

Chain-calling parent initialisers in python [duplicate]


Python 3 includes an improved super() which allows use like this:

super().__init__(args)


The way you are doing it is indeed the recommended one (for Python 2.x).

The issue of whether the class is passed explicitly to super is a matter of style rather than functionality. Passing the class to super fits in with Python's philosophy of "explicit is better than implicit".


You can simply write :

class A(object):    def __init__(self):        print "Initialiser A was called"class B(A):    def __init__(self):        A.__init__(self)        # A.__init__(self,<parameters>) if you want to call with parameters        print "Initialiser B was called"class C(B):    def __init__(self):        # A.__init__(self) # if you want to call most super class...        B.__init__(self)        print "Initialiser C was called"


matomo