[Tutor] Re: Instantiating a derived class

Lee Harr missive at hotmail.com
Mon Oct 6 18:07:34 EDT 2003


>Does the constructor need the same args as the parent class ?
>
>When instantiating an instance of a derived class, should the derived class
>constructor
>have the same args as the parent class constructor, as a minimum, as well
>as any args specifically required by the derived class ?
>


I would say... not necessarily, although that is certainly one way to do it.

Basically, until you know that you do not need to, you should be calling
the parent class's constructor in your child class.  Like this:


class Definition:
    def __init__(self, MacroFilename, Linenum, Context):
        self.Filename = MacroFilename
        self.FileLinenum = Linenum
        self.Context = Context


class Macro(Definition):
    def __init__(self, MacroName):
        mf = 'the_macrofilename'
        ln = 43
        ct = foo # not sure where you get this
        Definition.__init__(self, mf, ln, ct)
        self.MacroName = MacroName

_________________________________________________________________
Add photos to your e-mail with MSN 8. Get 2 months FREE*. 
http://join.msn.com/?page=features/featuredemail




More information about the Tutor mailing list