O'Reilly logo

Expert Python Programming - Second Edition by Tarek Ziadé, Michał Jaworski

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Accessing methods from superclasses

super is a built-in class that can be used to access an attribute belonging to an object's superclass.

Note

The Python official documentation lists super as a built-in function. But it's a built-in class, even if it is used like a function:

>>> super
<class 'super'>

Its usage is a bit confusing when you are used to accessing a class attribute or method by calling the parent class directly and passing self as the first argument. This is really old pattern but still can be found in some codebases (especially in legacy projects). See the following code:

class Mama:  # this is the old way
    def says(self):
        print('do your homework')

         
class Sister(Mama):
    def says(self):
        Mama.says(self)
        print('and clean your bedroom')

When ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required