Reputation: 8103
In python, what is super(classItSelf) doing?
I have a project to work on has code such as this:
class Tele(TcInterface):
_signal = signal.SIGUSR1
def __init__(self):
super(Tele, self).__init__()
self._c = None
What is this line doing?
super(Tele, self).__init__()
I am a cpp java code, Really got confused about python stuff.
Upvotes: 1
Views: 65
Reputation: 6333
you need to pass at least self
to __init__
.
python is different from some traditional OOP languages, which will handle self
or this
or whatever name you give to the current instance automatically for you.
in python, self
is exposed, even in constructor, so that you need to pass in and reference it yourself. and this super(...)
here, it basically looks for a proxy, which represents all super classes, and super(...).__init__
is referencing the constructors from the super classes. it's the same concept as you call super()
in C++ or Java.
please reference doc for more: https://docs.python.org/2/library/functions.html#super
Upvotes: 1
Reputation: 5945
This calls the __init__()
function (constructor) of the super/parent class (TclInterface
). This is often necessary, as the superclass constructor is otherwise overridden by __init__()
in the subclass.
Upvotes: 1