Cooperative methods, was Re: Calling __init__ with multiple inheritance
__peter__ at web.de
Mon Mar 28 17:10:08 CEST 2005
phil_nospam_schmidt at yahoo.com wrote:
> What if I want to call other methods as well? Modifying your example a
> bit, I'd like the reset() method call of Child to invoke both the
> Mother and Father reset() methods, without referencing them by name,
> i.e., Mother.reset(self).
The problem with that aren't incompatible signatures, but the lack of an
implementation of the reset() method at the top of the diamond-shaped
inheritance graph that does _not_ call the superclass method. That method
could be basically a noop:
# object does something similar for __init__()
print "resetting Mother"
print "resetting Father"
class Child(Mother, Father):
print "resetting Child"
It might sometimes be convenient if such methods would magically spring into
existence for the object class, but for now you have to do it manually (or
perhaps someone has come up with a metaclass that I am not aware of).
PS: See http://www.python.org/2.2/descrintro.html for more on the subject.
More information about the Python-list