I have a class AbstractDataHandle, whith his init method, and a class Classifier. I would like to have two constructors in Classifier, Java like. One inheri
You can use class methods, which work as factory methods. That's imho the best approach for multiple constructors. First argument 'cls' is class itself, not it's instance, so cls('Truck') in class method invokes constructor for class Car.
class Car(object):
def __init__(self, type='car'):
self.car_type = type
@classmethod
def Truck(cls):
return cls('Truck')
@classmethod
def Sport(cls):
return cls('Sport')
@classmethod
def Van(cls):
return cls('Van')
Then you call factory method this way:
mycar = Car.Sport()