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

Popular posts from this blog

image - ClassNotFoundException when add a prebuilt apk into system.img in android -

I need to import mysql 5.1 to 5.5? -

Java, Hibernate, MySQL - store UTC date-time -