npkp npkp - 2 months ago 20
Python Question

python super() function error?

class car(object):

def __init__(self, make, model, year):
self.make = make
self.model = model
self.year = year
self.odometer_reading = 0

class electricCar(car):
def __init__(self, make, model, year):
super().__init__(make, model, year)

tesla = electricCar('tesla', 'model s', 2016)
print tesla.get_descriptive_name()

TypeError: super() takes at least 1 argument (0 given)

what is the problem with the super() function ?

Que Que

super() (without arguments) was introduced in python3 In python2 you should Change it to this

class electricCar(car):
    def __init__(self, make, model, year):
        super(electricCar,self).__init__(make, model, year)

you could refer this question for general inheritance syntax issue regarding python2 and python3