使用 Python super 时遇到问题

仙女

所以我目前正在使用 Python Crash Course 一书学习 Python 的基础知识。我在关于类的章节,更准确地说是关于它的子类部分。首先,这是我的代码:

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)

因此,使用此代码,我收到此错误消息:

极好的()。init (constructeur, annee, modele) TypeError: super() 需要至少 1 个参数(给定 0)

我使用的代码和书中的代码相同(除了法语部分,书中是英文的)。我尝试使用和不使用“super()”的“pass”,并尝试给“super”参数“self”和“Car”。

我正在使用 Python 3,我在 linux 上。

提前感谢您的任何答案:)

什穆利克·阿萨菲

super() 语法是 Python 3 如果你还在使用 Python 2,你需要 super(ElectricCar, self)

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

使用Enthought Python安装IJulia时遇到问题

来自分类Dev

在C#中使用python webservice时遇到问题

来自分类Dev

在python中使用while循环时遇到问题

来自分类Dev

使用Python从AJAX获取数据时遇到问题

来自分类Dev

使用Python请求打开页面时遇到问题

来自分类Dev

我在使用 python 循环创建测验时遇到问题

来自分类Dev

在 Python 中使用 Selenium 单击按钮时遇到问题

来自分类Dev

在Python中使用SQLite遇到问题

来自分类Dev

使用Psycopg2将数据从python写入PostgreSQL时遇到问题

来自分类Dev

使用Python ctypes运行C dll函数时遇到问题(大小未知的数组输出)

来自分类Dev

包装和使用带有SWIG返回结构的函数时遇到问题(python)

来自分类Dev

使用python扩展名在gdb中打印本征类型时遇到问题

来自分类Dev

使用python在sqlite3中存储numpy数组时遇到问题

来自分类Dev

在Python中使用正则表达式识别和捕获文本时遇到问题

来自分类Dev

尝试使用request-html刮取JS网站时遇到问题(Python 3.6)

来自分类Dev

使用Python的SQLALCHEMY连接到Cloud SQL(PostgreSQL)时遇到问题

来自分类Dev

使用python configparser读取AWS配置文件时遇到问题

来自分类Dev

新手Python用户在使用简单功能时遇到问题

来自分类Dev

使用python 2.7对gdb-peda的支持来编译GDB时遇到问题

来自分类Dev

使用python向Solr添加数据时遇到问题吗?

来自分类Dev

使用python 3在树莓派2上运行pyfirmata时遇到问题

来自分类Dev

使用 python2.7 访问 Active Directory 时遇到问题

来自分类Dev

使用 python 和 selenium 从表中抓取数据时遇到问题

来自分类Dev

使用 tox 运行 python 单元测试时遇到问题 - 已安装模块的导入错误

来自分类Dev

使用beautifulsoup python从页面中抓取特定元素时遇到问题

来自分类Dev

使用 python 中的请求模块连接到 Azure-Datalakes-gen2 时遇到问题

来自分类Dev

使用super()时的继承问题(Python)

来自分类Dev

使用LIKE%...%时遇到问题

来自分类Dev

使用onLoad与.each()时遇到问题

Related 相关文章

  1. 1

    使用Enthought Python安装IJulia时遇到问题

  2. 2

    在C#中使用python webservice时遇到问题

  3. 3

    在python中使用while循环时遇到问题

  4. 4

    使用Python从AJAX获取数据时遇到问题

  5. 5

    使用Python请求打开页面时遇到问题

  6. 6

    我在使用 python 循环创建测验时遇到问题

  7. 7

    在 Python 中使用 Selenium 单击按钮时遇到问题

  8. 8

    在Python中使用SQLite遇到问题

  9. 9

    使用Psycopg2将数据从python写入PostgreSQL时遇到问题

  10. 10

    使用Python ctypes运行C dll函数时遇到问题(大小未知的数组输出)

  11. 11

    包装和使用带有SWIG返回结构的函数时遇到问题(python)

  12. 12

    使用python扩展名在gdb中打印本征类型时遇到问题

  13. 13

    使用python在sqlite3中存储numpy数组时遇到问题

  14. 14

    在Python中使用正则表达式识别和捕获文本时遇到问题

  15. 15

    尝试使用request-html刮取JS网站时遇到问题(Python 3.6)

  16. 16

    使用Python的SQLALCHEMY连接到Cloud SQL(PostgreSQL)时遇到问题

  17. 17

    使用python configparser读取AWS配置文件时遇到问题

  18. 18

    新手Python用户在使用简单功能时遇到问题

  19. 19

    使用python 2.7对gdb-peda的支持来编译GDB时遇到问题

  20. 20

    使用python向Solr添加数据时遇到问题吗?

  21. 21

    使用python 3在树莓派2上运行pyfirmata时遇到问题

  22. 22

    使用 python2.7 访问 Active Directory 时遇到问题

  23. 23

    使用 python 和 selenium 从表中抓取数据时遇到问题

  24. 24

    使用 tox 运行 python 单元测试时遇到问题 - 已安装模块的导入错误

  25. 25

    使用beautifulsoup python从页面中抓取特定元素时遇到问题

  26. 26

    使用 python 中的请求模块连接到 Azure-Datalakes-gen2 时遇到问题

  27. 27

    使用super()时的继承问题(Python)

  28. 28

    使用LIKE%...%时遇到问题

  29. 29

    使用onLoad与.each()时遇到问题

热门标签

归档