Python: call base class method from a derived class 

Joined:
04/09/2007
Posts:
775

May 31, 2009 03:19:00    Last update: July 16, 2010 19:37:07
For old-style classes: BaseClassName.methodname(self, arguments)
>>> class A:
...     def hello(self):
...         print 'a'
...
>>> A().hello()
a
>>> class C(A):
...     def hello(self):
...         A.hello(self)
...         print 'c'
...
>>> C().hello()
a
c


For new-style class (any class which inherits from object): super(ClassName, self).method(args)
>>> class M(object):
...     def hello(self):
...         print 'm'
...
>>> class N(M):
...     def hello(self):
...         super(N, self).hello()
...         print 'n'
...
>>> N().hello()
m
n


Reference:
Things to Know About Python Super
Share |
| Comment  | Tags