If you always want Grandfather#do_thing
, regardless of whether Grandfather
is Father
's immediate superclass then you can explicitly invoke Grandfather#do_thing
on the Son
self
object:
class Son(Father):
# ... snip ...
def do_thing(self):
Grandfather.do_thing(self)
On the other hand, if you want to invoke the do_thing
method of Father
's superclass, regardless of whether it is Grandfather
you should use super
(as in Thierry's answer):
class Son(Father):
# ... snip ...
def do_thing(self):
super(Father, self).do_thing()
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…