You can use super(ChildClass, self).__init__()
class BaseClass(object): def __init__(self, *args, **kwargs): pass class ChildClass(BaseClass): def __init__(self, *args, **kwargs): super(ChildClass, self).__init__(*args, **kwargs)
The fingerprint is incorrect, the code is changed here:
class Car(object): condition = "new" def __init__(self, model, color, mpg): self.model = model self.color = color self.mpg = mpg class ElectricCar(Car): def __init__(self, battery_type, model, color, mpg): self.battery_type=battery_type super(ElectricCar, self).__init__(model, color, mpg) car = ElectricCar('battery', 'ford', 'golden', 10) print car.__dict__
Here's the conclusion:
{'color': 'golden', 'mpg': 10, 'model': 'ford', 'battery_type': 'battery'}
Mingyu Oct 06 '13 at 6:06 on 2013-10-06 06:06
source share