Inheritance and Design Question

Terry Reedy tjreedy at
Wed May 27 17:21:23 EDT 2009

imageguy wrote:
> I have an object the I would like to use as a base class.  Some of the
> methods I would like to override completely, but others I would simply
> like to call the base class method and use the return value in the
> child method.  The purpose here is to eliminate the duplication of
> valuable code in the parent, when I really just need the child to
> operate of a results of the parent.
> Consider the following two classes;
> class Parent(object):
>     def process(self, value):
>         retval = "Parent.result('%s')" % value
>         return retval
> class Child(Parent):
>     def __init__(self):
>         Parent.__init__(self)

Delete this and the parent __init__ is called directly.
>     def process(self, value):
>         retval = "Child.result('%s')" % super(Child, self).process
> (value)
>         return retval

super() was designed for multiple inheritance.  The only reason I know 
to use it with single inheritance it to save a 
global-search-and-replace_with_confirmation if you change the name of 
the parent or change parents.  Unless I really anticipated such 
contigencies, I would probably write Parent.process(self, value).


More information about the Python-list mailing list