Potential improvement on delegation via explicit calls and super

Thomas Guettler guettli at thomas-guettler.de
Fri Dec 17 15:48:50 CET 2004

Am Fri, 17 Dec 2004 02:17:38 -0600 schrieb Robert Dick:

> Derived classes sometimes need to delegate portions of the work in overridden 
> methods to methods in their base classes.  This was traditionally done with 
> explicit calls in python, e.g.,
> class Base:
>   def __init__(self):
>     print 'base'
> class Left(Base):
>   def __init__(self, arg):
>     Base.__init__(self)
>     print 'left'
> class Right(Base):
>   def __init__(self, arg):
>     Base.__init__(self)
>     print 'right'

If you can change the source of Base, I would do it like

class Base:
    def __init__(self):
        if self._init_done:

        # ... do init


Thomas Güttler, http://www.thomas-guettler.de/

More information about the Python-list mailing list