0

I've got a simple test program like this:

__metaclass__=type
class b1:
    def __init__(s):
        print "world"
class b2:
    def __init__(s):
        print "hello"
class d(b1,b2):
    def __init__(s):
        super(d,s).__init__()
obj=d()

I expect that "d" construting will print out both "b1" and "b2" base classes "init" content, and thus I'll see "world hello"

But actually the result was just "world". I'm using python2.4.5

Any error in my understanding?

Troskyvs
  • 7,537
  • 7
  • 47
  • 115
  • You have to consistently use ``super(...).__init__()`` in ALL of your classes' constructors for this to work right. – jasonharper Dec 24 '16 at 03:59
  • This is python 2 and old style classes? – tdelaney Dec 24 '16 at 04:05
  • The issue is covered in [How does Python's super work with multiple inheritance?](http://stackoverflow.com/questions/3277367/how-does-pythons-super-work-with-multiple-inheritance), especially [the answer](http://stackoverflow.com/a/16310777/642070) that shows how to do cooperative subclassing. Add `super` calls to your first two classes and it starts working as you want. – tdelaney Dec 24 '16 at 04:12

0 Answers0