Question about inheritence

Jordan JordanNealBerg at gmail.com
Tue Jul 22 12:39:42 EDT 2008


On Jul 22, 12:26 pm, 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.

Well, the __init__ method of the subclass is called, and from within
it you can call the superclass constructor.

Here is a sample code:

class A():
     def __init__(self, bla):
            #do some stuff here

class B(A):
     def __init__(self, bla2):
          #do some stuff here
          A.__init__(self,bla)



More information about the Python-list mailing list