0

I am trying to to run the following piece of code, and I want C to initialize both A and B (and possible more) in a neat and dynamic manner.

class A(object):
    def __init__(self):
        print 'Class A init'

class B(object):
    def __init__(self):
        print 'Class B init'

class C(A, B):
    def __init__(self):
        super(C, self).__init__()
        print 'Class C init'

c = C()

However, this only outputs

 Class A init
 Class C init

I know that this is due to the depth-first search manner when invoking super(...), and it stops when first method was found. Can I in some way initialize all super classes?

Edit: Defining C as below achieves the goal of initializing all super classes. Is there a way to implicit initialize all super classes?

class C(A, B):
    def __init__(self):
        A.__init__(self)
        B.__init__(self)
        print 'Class C init'

Solution: As pointed out a super(B, self).__init__() was added in class B

YnkDK
  • 681
  • 9
  • 26

0 Answers0