We're back after a server migration that caused effbot.org to fall over a bit harder than expected. Expect some glitches.

How do I call a method defined in a base class from a derived class that overrides it?

If you’re using new-style classes, use the built-in super function:

class Base(object):
    def meth(self):
        pass    

class Derived(Base):
    def meth(self):
        super(Derived, self).meth()

If you’re using classic classes: For a class definition such as class Derived(Base): … you can call method meth() defined in Base (or one of Base’s base classes) as Base.meth(self, arguments…). Here, Base.meth is an unbound method, so you need to provide the self argument.

class Base:
    def meth(self):
        pass    

class Derived(Base):
    def meth(self):
        Base.meth(self)

CATEGORY: programming