Implicit __init__ execution in multiple inheritance

Bruno Desthuilliers bruno.42.desthuilliers at websiteburo.invalid
Tue Feb 16 16:12:36 CET 2010

Arnaud Delobelle a écrit :
> rludwinowski <rludwinowski at> writes:
>> class A:
>>     def __init__(self):
>>         print("A__init__")
>> class B:
>>     def __init__(self):
>>         print("B__init__")
>> class C(A, B):
>>     pass
>> C()
>>>> A__init__
>> Why __init__ class B will not be automatic executed?
> Because it's documented behaviour?  By default, at initialisation, an
> instance of C will go up the method resolution order and only execture
> the first __init__() method found.

Note to the OP : Python's "methods" are attributes, so the normal 
attribute lookup rules apply - which is why the lookup stops at the 
first (in _mro_ order) '__init__' method found.

More information about the Python-list mailing list