python - Calling a parent's parent's method, which has been overridden by the parent -
how call method more 1 class inheritance chain if it's been overridden class along 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 grandfather stuff class son(father): def __init__(self): super(son, self).__init__() def do_thing(self): # how grandfather?
if want grandfather#do_thing
, regardless of whether grandfather
father
's immediate superclass can explicitly invoke grandfather#do_thing
on son
self
object:
class son(father): # ... snip ... def do_thing(self): grandfather.do_thing(self)
on other hand, if want invoke do_thing
method of father
's superclass, regardless of whether grandfather
should use super
(as in thierry's answer):
class son(father): # ... snip ... def do_thing(self): super(father, self).do_thing()
Comments
Post a Comment