How can I use another constructor in a derived class in Python?
If I try something like this:
from abc import ABCMeta, abstractproperty, abstractmethod
class AbstractClass(object):
__metaclass__ = ABCMeta
def __init__(self):
pass
and
import AbstractClass
class DerivedClass(AbstractClass):
_prop = ''
def __init__(self, param):
self._prop = param
I get
TypeError: Error when calling the metaclass bases
module.__init__() takes at most 2 arguments (3 given)
I would like to do something like
if (cl_param == '1'):
obj = DerivedClass1('1', 'c')
else if (cl_param == '2'):
obj = DerivedClass2('2', 'foo', 2)
etc. The rest of the interface would be the same in every class, they just need different initialization parameters. Or do I need to get around this by specifying options in the list?
source
share