[Tutor] Calling method in parent class

Alan Gauld alan.gauld at btinternet.com
Wed May 13 11:00:14 CEST 2009


"spir" <denis.spir at free.fr> wrote 

>> But calling the method of a superclass from the same method is very, 
>> very common.
> 
> Yep, for sure; and I was not discussing this actually.
> (1) In fact, the whole exchange started when the OP asked how to 
> call 2 different methods on the same object, one beeing defined 
> on on its own class, the other one on the parent class. 

No he was asking about calling the supercall version of the same 
method. Here is the post:

-------------
class Child(Parent):
    def somemethod( self, bla ):
        Parent.somemethod(self,bla)
-------------

It uses somemethod() in both child and parent.

And that is what I am saying is a very common, and desirable, pattern.

I may be coming across a bit strong on this one but it is such a 
fundamentally important feature of OOP that I feel on a list like tutor
it is important to make it clear that this is not only correct behaviour 
but is very common in practice.

-- 
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/



More information about the Tutor mailing list