2017-06-23 51 views
0

私は現在Pythonのクラッシュコースを使って、Pythonの基礎を学んでいます。 私はクラスについての章、より正確にはそのサブクラスの部分について説明します。私は、このエラーメッセージが表示されます。このコードで、Pythonを使ったトラブルsuper

class Car(): 
"""une representation simpliste de voiture""" 

def __init__(self, constructeur, annee, modele): 
    self.constructeur = constructeur 
    self.modele = modele 
    self.annee = annee 
    self.odometer_reading = 0 

def descriptive_name(self): 
    long_name = str(self.annee) + ' ' + self.constructeur + ' ' + self.modele 
    return long_name.title() 

def update_odometer(self, mileage): 
    """set odometer reading""" 

    if mileage >= self.odometer_reading: 
     self.odometer_reading = mileage 
    else: 
     print("You can't roll back and odometer!\n") 

def increment_odometer(self, miles): 
    self.odometer_reading += miles 

def read_odometer(self): 
    """print mileage""" 
    print("this car has " + str(self.odometer_reading) + " miles on it.\n") 
class ElectricCar(Car): 
def __init__(self, constructeur, annee, modele): 
    super().__init__(constructeur, annee, modele) 
    pass 
my_tesla = ElectricCar('tesla', 'model s', 2016) 

ので: だから最初に、ここに私のコードです

super().init(constructeur, annee, modele) TypeError: super() takes at least 1 argument (0 given)

私が使用するコードは、フランスの一部を除いて(書籍の場合と同様です、それは本に英語で書かれています)。 "super()"の "pass"を試してみましたが、 "super"に "self"と "Car"という引数を与えようとしました。

私はPython 3を使用しています。私はLinuxです。すべての答えを事前に

感謝:)

+2

を必要とする 'super'は異なった動作Python 2とPython 3の間でどのバージョンを使用していますか?このチュートリアルは、Python 3で動作するように設計されている可能性があります。 – Kevin

+0

...そして、Python 2を学ぶ良い理由がない限り、Python 3を学んでいるのは間違いありません。それともPythonで書かれたコードベースに貢献したいのですか?2) –

+0

質問したとおりに編集したところです: 私はPython 3を使用しています – Taewyth

答えて

2

あなたはまだPythonの2を使用している場合は、スーパー()構文は、Python 3 である、あなたはスーパー(ElectricCar、自己)

関連する問題