Understanding Python super() with __init__() methods
super() lets you avoid referring to the base class explicitly, which can be nice. But the main advantage comes with multiple inheritance, where all sorts of fun stuff can happen.
EXIT-LYON Energy provides industrial & commercial energy storage, solar PV for mining, ports, oilfields, railways, airports, hospitals, schools, microgrids, and emergency backup systems.
super() lets you avoid referring to the base class explicitly, which can be nice. But the main advantage comes with multiple inheritance, where all sorts of fun stuff can happen.
super() is a special use of the super keyword where you call a parameterless parent constructor. In general, the super keyword can be used to call overridden methods, access hidden
In fact, multiple inheritance is the only case where super() is of any use. I would not recommend using it with classes using linear inheritance, where it''s just useless overhead.
As for chaining super::super, as I mentionned in the question, I have still to find an interesting use to that. For now, I only see it as a hack, but it was worth mentioning, if only for the differences with Java
Thirdly, when you call super() you do not need to specify what the super is, as that is inherent in the class definition for Child. Below is a fixed version of your code which should perform
Python 3 super makes an implicit reference to a "magic" __class__ [*] name which behaves as a cell variable in the namespace of each class method.
If your object doesn''t fit in it''s super class, then you need to add it to the "grandparent class", create a new class, or find another super it does fit into. Personally, I have found this limitation
It seems that object itself violates one of the best practices mentioned in the document, which is that methods which use super must accept *args and **kwargs. Now, obviously Mr. Knight