Question about inheritence

Scott David Daniels Scott.Daniels at Acm.Org
Wed Jul 23 06:32:00 CEST 2008


Fredrik Lundh wrote:
> Catherine Heathcote wrote:
> 
>> If I create a new class inherited from another with a constructor, what
>> happens with the new class's constructer?
> Python doesn't really have constructors; when you create an object, 
> Python first creates the object and then calls the __init__ method, if 
> available

To elaborate a bit on Fredrik's response, there is a sense in which
Python has constructors, but, to the extent it does, a constructor is
the __new__, __init__ pair.  For immutables, everything happens in
__new__, for mutables, most things happen in the __init__ chain.

--Scott David  Daniels
Scott.Daniels at Acm.Org



More information about the Python-list mailing list