Defining class attributes + inheritance

Martin De Kauwe mdekauwe at gmail.com
Tue Mar 8 17:51:10 EST 2011


Hi,

I think this might be obvious? I have a base class which contains X
objects which other classes inherit e.g.

class BaseClass(object):
    def __init__(self, something, something_else):
        self.something = something
        self.something_else = something_else
        # etc

Typically I would use this like this

from some_module_name import BaseClass

class NewClass(BaseClass):
    def do_something(self):
         print self.something
         # etc

Which is fine. However if I need to inherit additional attributes (to
NewClass) at the constructor step it means I have to completely
redefine the constructor and therefore can't inherit in this way,
which defeats the purpose of defining a default base class. Am I being
slow is there a nice solution to this or is that the way it works?

thanks,

Martin



More information about the Python-list mailing list