[Tutor] super() vs. explicitly calling base class?
DL Neil
PyTutor at danceswithmice.info
Sat Sep 21 04:23:42 EDT 2019
On 21/09/19 4:47 PM, boB Stepp wrote:
> Python 3.7.4 on Linux Mint
>
> Assumption: I have only TWO classes (Not concerned about 3+ class
> inheritance scenario), Base and Child. Is there any advantage to
> using super() over explicitly calling Base from within Child? My
> following trivial example does not suggest any difference:
>
>>>> class Base:
> def __init__(self):
> print("This is the Base class!")
>>>> class Child(Base):
> def __init__(self):
> print("This is the Child class!")
> def call_base(self):
> print("About to call the Base class with super!")
> super().__init__()
> print("Now explicitly calling the Base class!")
> Base.__init__(self)
super() is usually considered the more 'pythonic'.
Should the name of the super class ever change, the Child class
declaration will need to be changed accordingly. However, nothing else.
If the super class is mentioned by name, then in that case every mention
of the name would have to be changed.
That said, how often are classNMs changed?
--
Regards =dn
More information about the Tutor
mailing list