Multiple inheritance with a common base class

Markus Bertheau twanger at
Tue Aug 10 14:19:05 CEST 2004

В Втр, 10.08.2004, в 13:37, Markus Bertheau пишет:

Also I observe that the instance will in fact _not_ have a single copy
of the data attributes used by the common base class. The following
example demonstrates this:

class CommonBase:
    def __init__(self): = 0
    def setNo(self, no): = no
class LeafA(CommonBase):
    def __init__(self):
        print(" %i" %
        CommonBase.setNo(self, 3)
class LeafB(CommonBase):
    def __init__(self):
        print(" %i" %
        CommonBase.setNo(self, 4)
class Multi(LeafA, LeafB):
    def __init__(self):
m = Multi()

It outputs: 0 0

If there was only one copy of the common base class, I'd have expected
an output similar to 0 3

This renders multiple inheritance pretty useless for me.

Can someone clear this all up and tell me how multiple inheritance is
supposed to work in python?


Markus Bertheau <twanger at>

More information about the Python-list mailing list