method overriding trick
nospam at bitbucket.com
Sat Nov 13 09:58:32 CET 1999
Jeremy Hylton wrote in message
<14378.62498.649973.150075 at bitdiddle.cnri.reston.va.us>...
>Overriding methods of a base class is a little clunky in Python. You
>need to explicitly name the base class that implements the method, and
>you call its as an unbound method, passing self as the first argument.
>Example: Base.aMethod(self, arg)
and suggested using
> super_aMethod = Base.aMethod
> def aMethod(self, arg):
> return self.super_aMethod(arg) + 1
>It doesn't solve the must-name-the-base-class problem, but it helps
>manage it better. If you keep the override assignments at the top of
>the class statement, then you only have one place to look in each
>class when the inheritance hierarchy changes.
I use a method that doesn't remove the clunkiness, but localises the
hierarchy to one line:
_Parent = basedlg.BaseDlg
def __init__(self, param):
self.local = param
By using the same name "_Parent" in all modules, less thinking is needed,
and cut'n'paste coding (what, me?) works better too.
Phil Mayes pmayes AT olivebr DOT com
Olive Branch Software - home of Arranger
More information about the Python-list