using super() to call two parent classes __init__() method

7stud bbxx789_05ss at yahoo.com
Fri Aug 17 01:30:19 EDT 2007


When I run the following code and call super() in the Base class's
__init__ () method,  only one Parent's __init__() method is called.


class Parent1(object):
    def __init__(self):
        print "Parent1 init called."
        self.x = 10

class Parent2(object):
    def __init__(self):
        print "Parent2 init called."
        self.y = 15

class Base(Parent1, Parent2):
    def __init__(self):
        super(Base, self).__init__()
        self.z = 20

b = Base()

--output:--
Parent1 init called.




More information about the Python-list mailing list