extending methods ?

Stephen Horne $$$$$$$$$$$$$$$$$ at $$$$$$$$$$$$$$$$$$$$.co.uk
Thu Oct 2 00:17:27 EDT 2003


On Wed, 1 Oct 2003 09:45:45 +0200 (CEST), Arnd Baecker
<arnd.baecker at web.de> wrote:

>the summary of my question is:
>is there a way to append commands to a method inherited from
>another class?

If you can call...

  instance.method (arg1, ...)

then you can equivalently call...

  classname.method (instance, arg1, ...)

You can use this in your subclasses method to call the method from a
specified base class (with multiple inheritance there may be more than
one base). For example...

>>> class A (object) :
...   def dostuff (self) :
...     print "running A.dostuff"
...
>>> class B (A) :
...   def dostuff (self) :
...     print "running B.dostuff"
...     A.dostuff (self)
...
>>> b=B()
>>> b.dostuff()
running B.dostuff
running A.dostuff


-- 
Steve Horne

steve at ninereeds dot fsnet dot co dot uk




More information about the Python-list mailing list