Question about inheritence

Matimus mccredie at gmail.com
Tue Jul 22 12:35:58 EDT 2008


On Jul 22, 9:26 am, Catherine Heathcote
<catherine.heathc... at gmail.com> wrote:
> If I create a new class inherited from another with a constructor, what
> happens with the new class's constructer?
> Thanks for your time.

Nothing, unless you call it in your constructor.

class Base(object):
 def __init__(self):
  print "Base constructor called"

# without calling the base class constructor
class C(Base):
 def __init__(self):
  print "C constructor called"

# call the base class constructor using super
class D(Base):
 def __init__(self):
  super(D, self).__init__()
  print "D constructor called"

c = C()
d = D()


Matt



More information about the Python-list mailing list