[Tutor] HELP: subclass of int

jfouhy at paradise.net.nz jfouhy at paradise.net.nz
Tue Mar 8 23:40:11 CET 2005

Quoting Max Noel <maxnoel_fr at yahoo.fr>:

> 	I'm not absolutely confident with inheritance in Python (nearly all of
> my serious OO work has been in Java), but shouldn't the call to the 
> superclass's constructor be the very first statement of the subclass's 
> constructor?

No ...

Or, well, maybe --- but __init__ is technically not the constructor.

The constructor is responsible for doing the nitty gritty work of constructing
an object, which is, I guess, why you feel it should be called first (because
you don't want to be messing with an object that does not fully exist yet).

But in python, by the time __init__ is called, the object has been fully
constructed.  __init__ is just a special method that gets called immediately
after construction.  But otherwise, there is nothing special or magical about it.

You could even do this if you wanted:

class myClass(object):
 def reInitialise(self):

although I'm not sure if this would be considered good practice :-)

[as to the original question --- someone else will have to answer, sorry, 'cause
I don't know]


More information about the Tutor mailing list