You can always call the code on the parent using the super() function . He gives a link to the parent. So, to call parent_method() , you must use super().parent_method() .
Here is a code snippet (for python3) that shows how to use it.
class ParentClass: def f(self): print("Hi!"); class ChildClass(ParentClass): def f(self): super().f(); print("Hello!");
In python2, you need to call super with additional arguments: super(ChildClass, self) . Thus, the fragment will be as follows:
class ParentClass: def f(self): print("Hi!"); class ChildClass(ParentClass): def f(self): super(ChildClass, self).f(); print("Hello!");
If you call f() on an instance of ChildClass, it will show: "Hello! Hello!".
If you are already encoded in java, this is basically the same behavior. You can call super wherever you want. In the method, in the function init, ...
There are other ways to do this , but it is less clean . For example, you can:
ParentClass.f(self)
Calling the function f of the parent class.
source share