Class __init__ behaviour

T

Thomas Bartkus

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.

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.

Did I get that straight?
Thomas Bartkus
 
D

Diez B. Roggisch

Thomas said:
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
 
L

Lou Pecora

"Thomas Bartkus said:
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.

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.

Did I get that straight?
Thomas Bartkus


Sounds right to me. That's how I use it.

-- Lou Pecora (my views are my own) REMOVE THIS to email me.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,294
Messages
2,571,508
Members
48,193
Latest member
DannyRober

Latest Threads

Top