class super method
ed at leafe.com
Tue Apr 1 04:41:37 CEST 2008
On Mar 31, 2008, at 5:58 PM, George Sakkis wrote:
>> is there any tutorial for super method (when/how to use it)?
>> or maybe someone could explain me how it works?
> Super is one of the dark corners of the language [1,2]... a good rule
> of thumb is to stay away from it, or at least stick to its basic
I disagree - super is quite elegant and dependable.
Because Python support multiple inheritance, it is difficult to
manually ensure that when augmenting a method that the correct
superclass calls are made. super() handles that without having to
guess as to what the correct inheritance hierarchy is.
In my own project (Dabo), we use mixin classes liberally to provide
consistent behavior across our UI classes. The use of super makes
customizing __init__() behavior, for example, quite straightforward.
The general form looks like:
class DaboUIClass(dabo.ui.dControlMixin, someWxPythonClass):
def __init__(self, *args, **kwargs):
super(DaboUIClass, self).__init__(*args, **kwargs)
This has worked reliably for us in every place where we have used it.
There's nothing dark and mysterious about it at all.
-- Ed Leafe
More information about the Python-list