Question about inheritence
Catherine Heathcote
catherine.heathcote at gmail.com
Tue Jul 22 12:37:39 EDT 2008
On Tue, 22 Jul 2008 09:35:58 -0700, Matimus wrote:
> 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
Aha! Makes sence, thankyou. As you can probably tell I am new to Python,
but not programming as a whole.
More information about the Python-list
mailing list