OOP in python

Thomas Wouters thomas at xs4all.net
Wed Mar 12 16:10:58 CET 2003

On Wed, Mar 12, 2003 at 08:45:51AM -0600, sismex01 at hebmex.com wrote:
> > From: bobnotbob at byu.edu [mailto:bobnotbob at byu.edu]
> > Sent: Wednesday, March 12, 2003 8:41 AM

> > What exactly do you inherit from another class in python?
> *EVERYTHING* is inherited.

> The thing is that parent class initializers are not automagically
> called, since their signature might be different from the child
> class' __init__.

Note that you only need to call the parent's (or parents') __init__ if you
supply an __init__ yourself; otherwise, standard method resolution is to
find the right __init__ to call.

>>> class A:
...     def __init__(self): print "A.__init__"
>>> class B(A): pass
>>> class C(A):
...     def __init__(self): print "C.__init__"
>>> A()
<__main__.A instance at 0x811c58c>
>>> B()
<__main__.B instance at 0x816648c>
>>> C()
<__main__.C instance at 0x811c58c>

Thomas Wouters <thomas at xs4all.net>

Hi! I'm a .signature virus! copy me into your .signature file to help me spread!

More information about the Python-list mailing list