How do you call a method more than one class up the inheritance chain if it's been overridden by another class along the way?
class Grandfather(object):
def __init__(self):
pass
def do_thing(self):
# stuff
class Father(Grandfather):
def __init__(self):
super(Father, self).__init__()
def do_thing(self):
# stuff different than Grandfather stuff
class Son(Father):
def __init__(self):
super(Son, self).__init__()
def do_thing(self):
# how to be like Grandfather?
If you always want
Grandfather#do_thing
, regardless of whetherGrandfather
isFather
's immediate superclass then you can explicitly invokeGrandfather#do_thing
on theSon
self
object:On the other hand, if you want to invoke the
do_thing
method ofFather
's superclass, regardless of whether it isGrandfather
you should usesuper
(as in Thierry's answer):You can do this using: