python - How to call super method? -


i working code has 3 levels of class inheritance. lowest level derived class, syntax calling method 2 levels hierarchy, e.g. super.super call? "middle" class not implement method need call.

well, 1 way of doing it:

class grandparent(object):     def my_method(self):         print "grandparent"  class parent(grandparent):     def my_method(self):         print "parent"  class child(parent):     def my_method(self):         print "hello grandparent"         grandparent.my_method(self) 

maybe not want, it's best python has unless i'm mistaken. you're asking sounds anti-pythonic , you'd have explain why you're doing give happy python way of doing things.

another example, maybe want (from comments):

class grandparent(object):     def my_method(self):         print "grandparent"  class parent(grandparent):     def some_other_method(self):         print "parent"  class child(parent):     def my_method(self):         print "hello grandparent"         super(child, self).my_method() 

as can see, parent doesn't implement my_method child can still use super @ method parent "sees", i.e. grandparent's my_method.


Comments

Popular posts from this blog

php - Zend Framework / Skeleton-Application / Composer install issue -

c# - Better 64-bit byte array hash -

python - PyCharm Type error Message -