Reputation: 11
class SimpleRoundedCorners(QWidget):
def __init__(self):
super(SimpleRoundedCorners, self).__init__()
self.initUI()
This makes no sense to me. I've read how super() works, and maybe I'm just not good enough at objects to grasp it. This seems like a very redundant call. Why am I calling init twice on the same object?
Upvotes: 1
Views: 92
Reputation: 1404
In OOP, super()
is very useful for the purpose of multiple-inheritance. It gives you access to methods and attributes from a superclass, to be used in a sub/child class, which saves a lot of time and effort.
The second init
call is used to access the superclass from the base/sub class. Where you pass in the arguments required by the superclass's init
constructor; such that when you instantiate the base/sub class, you only pass in the arguments required by its init
constructor only, not the arguments required for the superclass's init
constructor. A nice example of that is looking at the implementation in this answer.
Moreover, you can just write super().__init__()
without explicitly referring to the base class.
Upvotes: 1