[Python] Why aren't superclass __init__ methods automatically invoked?

Discussão em 'Python' iniciado por Stack, Agosto 16, 2025.

  1. Stack

    Stack Membro Participativo

    Why did the Python designers decide that subclasses' __init__() methods don't automatically call the __init__() methods of their superclasses, as in some other languages? Is the Pythonic and recommended idiom really like the following?

    class Superclass(object):
    def __init__(self):
    print 'Do something'

    class Subclass(Superclass):
    def __init__(self):
    super(Subclass, self).__init__()
    print 'Do something else'

    Continue reading...

Compartilhe esta Página