[Tutor] How arguments to the super() function works?

eryk sun eryksun at gmail.com
Sun May 19 09:15:59 EDT 2019


On 5/19/19, Arup Rakshit <ar at zeit.io> wrote:
>
> class Dad:
>     def can_i_take_your_car(self):
>         print("No...")
>
> class Mom(Dad):
>     def can_i_take_your_car(self):
>         print("Asking your dad...")
>
> class Victor(Mom, Dad):
>     def can_i_take_your_car(self):
>         print("Asking mom...")
>
> class Pinki(Mom, Dad):
>     def can_i_take_your_car(self):
>         print("I need it today..")
>
> class Debu(Pinki, Victor):
>     def can_i_take_your_car(self):
>         super(Victor, self).can_i_take_your_car()
>
> In this piece of code:
>
> print(Debu().can_i_take_your_car())
>
> Why the above call prints "Asking your dad…” but not " print("Asking mom…”)”
> although can_i_take_your_car is defined inside the class Victor ?

Victor comes after Pinki in the MRO:

    >>> super(Debu, Debu()).can_i_take_your_car()
    I need it today..
    >>> super(Pinki, Debu()).can_i_take_your_car()
    Asking mom...
    >>> super(Victor, Debu()).can_i_take_your_car()
    Asking your dad...
    >>> super(Mom, Debu()).can_i_take_your_car()
    No...

> Last question: Why duplicate PEPs for the same thing
> https://www.python.org/dev/peps/pep-0367/ and
> https://www.python.org/dev/peps/pep-3135/#specification ? Which one to read
> when such duplicate exists?

See https://www.python.org/dev/peps/pep-0367/#numbering-note and
https://www.python.org/dev/peps/pep-3135/#numbering-note.


More information about the Tutor mailing list