basic inheritance question

Mats Wichmann mats at laplaza.org
Mon Sep 24 19:48:56 EDT 2001


On Thu, 20 Sep 2001 13:12:24 -0700 (PDT), "Sean 'Shaleh' Perry"
<shalehperry at home.com> wrote:

:
:On 20-Sep-2001 Nathan Valentine wrote:
:> Thanks to everyone who pointed out that I was not calling the __init__
:> of the baseclass.
:> 
:> BTW, I don't recall seeing any mention of having to do this when
:> reading the Python Tutorial authored by Guido. I did another quick
:> scan of the doc and still don't see it. Perhaps this is something that
:> should be added to the Notes for the section on classes and
:> inheritance?
:
:It says this but is not very explicit (last paragraph in the section on
:inheritcance).  If you define a method that is also defined in the base class
:only the new method is called.  You must call BaseClass.method() to get the base
:class's method called.  This applies to __init__ and other __foo__ methods. 
:However in a tutoruial this should be more explicit.

Well,  you only need to arrange to call the base class constructor if
it's really needed, so it's not a mandatory step.  In general, most of
the construction of an instance is done by the language anyway,
Python's __init__ is the way you can supply additional
construction-time steps. It feels to me like it's better to describe
the Python inheritance mechanism as several pieces (some from the base
class, some from the derived class) contributing to a class - and that
class often has only one construction method, then a set of cascading
defintions.


Mats Wichmann




More information about the Python-list mailing list