<p><br>
On Mar 8, 2011 6:02 PM, "Martin De Kauwe" <<a href="mailto:mdekauwe@gmail.com">mdekauwe@gmail.com</a>> wrote:<br>
><br>
> Hi,<br>
><br>
> I think this might be obvious? I have a base class which contains X<br>
> objects which other classes inherit e.g.<br>
><br>
> class BaseClass(object):<br>
>    def __init__(self, something, something_else):<br>
>        self.something = something<br>
>        self.something_else = something_else<br>
>        # etc<br>
><br>
> Typically I would use this like this<br>
><br>
> from some_module_name import BaseClass<br>
><br>
> class NewClass(BaseClass):<br>
>    def do_something(self):<br>
>         print self.something<br>
>         # etc<br>
><br>
> Which is fine. However if I need to inherit additional attributes (to<br>
> NewClass) at the constructor step it means I have to completely<br>
> redefine the constructor and therefore can't inherit in this way,<br>
> which defeats the purpose of defining a default base class. Am I being<br>
> slow is there a nice solution to this or is that the way it works?<br>
><br>
> thanks,<br>
><br>
> Martin</p>
<p>Why does overriding the constructor make inheritance useless? You just have to call the superclass's constructor, same as in every other OOP language I've used. You can use *args and **kwargs to avoid relisting all the superclass's arguements.</p>

<p>def __init__(self, newarg, *args, **kwargs):<br>
    BaseClass.__init__(self, *args,**kwargs)<br>
    self.newarg = newarg</p>
<p>> --<br>
> <a href="http://mail.python.org/mailman/listinfo/python-list">http://mail.python.org/mailman/listinfo/python-list</a><br>
</p>