"Chris Lambacher" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > On Wed, Jul 26, 2006 at 09:21:10AM -0700, [EMAIL PROTECTED] wrote: > > 'Learning Python' by Lutz and Ascher (excellent book by the way) > > explains that a subclass can call its superclass constructor as > > follows: > > > > class Super: > > def method(self): > > # do stuff > > > > class Extender(Super): > > def method(self): > > Super.method(self) # call the method in super > > # do more stuff - additional stuff here > >
With new-style classes (where Super inherits from object), I think the preferred style is now: super(Extender,self).__init__(**kwargs) Instead of Super.__init__(self,**kwargs) class Super(object): def __init__(self, **kargs): print kargs self.data = kargs class Extender(Super): def __init__(self, **kargs): #~ Super.__init__(self, **kargs) # call the constructor method in Super super(Extender,self).__init__(**kargs) e = Extender(a=123) prints: {'a': 123} -- Paul -- http://mail.python.org/mailman/listinfo/python-list