super() in Python 3

DL Neil PythonList at DancesWithMice.info
Wed Jul 17 16:53:15 EDT 2019


On 16/07/19 10:08 PM, אורי wrote:
> Hi,
> 
> 1. When we use super() in Python 3, we don't pass it the first argument
> (self). Why?
> 
> What happens if the first argument is not self?
> 
> def __init__(self, *args, **kwargs):
>      super().__init__(*args, **kwargs)
> 
> I think it would make more sense to use something like
> self.super().__init__(*args, **kwargs) or something like this.

NB folk coming to Python from other (programming) languages are often 
surprised to discover that a sub-class does not automatically execute 
the initialiser/constructor of its parent. The extra control offered is 
(IMHO) both subtle and powerful!


I'm not sure about this (and perhaps better minds will clarify):
isn't self about an instance, whereas super() is about a class?


Another way to look at it is to refer to the super-class as the 
'parent'. Thinking of yourself, do?did you address him as "my father" 
(self.father) or her as "my mother", or is the possessive description 
(the "my"), unnecessary?

Whilst it wouldn't be at all wrong to address him as "my father", in 
English (and/or in other tongues), what happened when you tried it in 
Python?


Perhaps then, we only use the "my" descriptor when we need to 
distinguish between multiple parents, eg yours cf mine? Even with 
multiple-inheritance*, Python's "MRO" saves us from needing to do that!
* yes Python can, even if xyz-other-language couldn't!


(Python's ability to track all this sounds like something from the xkcd 
Comic: with Python you will never again cry, "I've lost my mummy"...)
-- 
Regards =dn



More information about the Python-list mailing list