[Tutor] why BaseClass.__init__ needs to be called explicitly?

alan.gauld@bt.com alan.gauld@bt.com
Mon, 17 Dec 2001 18:35:05 -0000

> 1. I was just wondering why does'nt python call the base 
> class constructor automatically like in java? 

Theres several ways to view this, first __init__() 
isn't really a constructor - its called *after* the 
class is constructed. Its an initialisation hook...

Secondly, Java is unusual in this regard if it calls 
superclass constructors implicitly(I didn't actually 
realise it did that!). C++ which does have 
constructors and several other compiled languages 
require explicit calling of the base class constructor.

There is an advantage to this in that you can 
effectively override the base constructor, 
although its a fairly dangerous thing to do IMHO!

> I noticed that it does provided i don't've a
> __init__() in the derived class.

Thats because being an initialisation function it
gets called automatically after creation. Python 
just calls self.__init__() and that goes through 
the usual python tree search for a version of 
init() to run if none exists in the immediate 

> Is there any specific reason behind this...

Its a good thing coz it offers more control to
the programmer.

> something to do with scripting languages?

Nope, nothing to do with scripting per se.

> 2. do we have a search facility on tutor/python-list sites? 

The ActiveState archive is searchable.

Alan G