subclassing "file"

James Henderson james at
Mon Jan 19 17:56:45 CET 2004

On Monday 19 January 2004 4:14 pm, Uwe Mayer wrote:
> when extending a build in class, what does the constructor __init__(...)
> have to return?

A bit more detail now I've read your message properly. :)  It shouldn't have a 
return statement.  This means that it returns None.

Strictly speaking __init__ isn't a constructor, since the instance has already 
been created before being passed to it.  (A real constructor, __new__, has 
been added to the language for subclassing immutable types.)  __init__ just 
modifies self in place.

> and how does the constructor call its base-class construtor? (or is this
> done automatically?)

The __init__ method of the base class, assuming it must be called at all, must 
be called explicitly as an unbound method, as I showed in my last e-mail.  
Reminder: if "self.__init__()" is the bound method then 
"MyClass.__init__(self)" is the unbound method.  The two are generally 
equivalent, but the unbound form is needed in inheritance to specify a 
superclass of self's immediate class.

James Henderson, Logical Progression Ltd.

More information about the Python-list mailing list