[Tutor] Using superclass __init__ method

Jan Eden lists at janeden.org
Thu Sep 22 16:42:59 CEST 2005

Kent Johnson wrote on 22.09.2005:

>This is standard behavior for any class attribute - if it's not
>defined in the derived class, the base class is checked. It's not
>special for __init__.
>I can't find a comprehensive reference for the way attribute lookup
>works - anyone else?

Well, I did know that any attribute used explicitly with a class instance is looked up in the class, then the base class etc:

class Base:
    variable = 1
class Child(Base):

child = Child()
print child.variable

What I did not know was that the __init__ method behaves the same way - i.e. that Python looks for __init__ upon instantiation until it finds one.


A good programmer is someone who looks both ways before crossing a one-way street. - Doug Linder

More information about the Tutor mailing list