How to inheritance overwrite non virtual?

Richie Hindle richie at entrian.com
Thu Sep 18 11:56:48 EDT 2003


[Axel]
> The mother-class is calling the method of the child-class, not
> it own method. I want the mother-method to be called like "the
> chield never was existing", but I find no way.

class A:
    def bwahHaHa(self):
        """When called by callMe(), derived classes don't get a look in."""
        print "Bwah-Ha-Ha!"
    
    def callMe(self):
        """Calls non-overridable method bwahHaHa()."""
        A.bwahHaHa(self)   ########## This is the interesting bit ##########

class B(A):
    def bwahHaHa(self):
        """Vain attempt to override what callMe() does."""
        print "Squeak"

b = B()
b.callMe()      # Prints "Bwah-Ha-Ha!"
b.bwahHaHa()    # Prints "Squeak"

-- 
Richie Hindle
richie at entrian.com






More information about the Python-list mailing list