Class __init__ behaviour

Diez B. Roggisch deets at nospam.web.de
Thu Apr 20 13:08:04 EDT 2006


Thomas Bartkus schrieb:
> If I insert an __init__ method in my own class definition, it is incumbent
> upon me to call the __init__ of any declared ancester to my new class object
> because my __init__ will override that of any ancester I declare in the
> header.  If I fail to call the ancesters __init__, then it won't happen.
> The ancester object won't be initialized.
Yes.


>    But
> 
> If I *don't* insert my own __init__ in my new class, then any declared
> ancester __init__ will automatically run because I haven't overridden the
> ancesters __init__ method with my own.

No. Only the __init__ of the leftmost ancestor is called. Of course if 
that uses the super(..)-method the other constructors get called.

Diez



More information about the Python-list mailing list