StrawberryZz 2023-02-25 20:12 采纳率: 100%
浏览 93
已结题

TypeError: object.__init__() takes exactly one argument (the instance to initialize)

求解答

报错如下:

Traceback (most recent call last):
  File "C:\Users\82791\Desktop\python_work\第9章\privileges.py", line 21, in <module>
    eric = Admin('eric', 'matthes', 'e_matthes', 'e_matthes@example.com', 'alaska')
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\82791\Desktop\python_work\第9章\privileges.py", line 19, in __init__
    super().__init__(first_name, last_name, username, email, location)
TypeError: object.__init__() takes exactly one argument (the instance to initialize)

代码如下:

class User:
    """一个表示用户的简单类。"""

def __init__(self, first_name, last_name, username, email, location):
    """初始化用户。"""
    self.first_name = first_name.title()
    self.last_name = last_name.title()
    self.username = username
    self.email = email
    self.location = location.title()
    self.login_attempts = 0


class Admin(User):
    """有管理权限的用户。"""

    def __init__(self, first_name, last_name, username, email, location):
        """初始化管理员。"""
        super().__init__(first_name, last_name, username, email, location)
    
eric = Admin('eric', 'matthes', 'e_matthes', 'e_matthes@example.com', 'alaska')
eric.describe_user()

  • 写回答

3条回答 默认 最新

  • 快乐鹦鹉 2023-02-25 20:25
    关注

    第4行初始化函数你得缩进啊,怎么能跟class对齐呢

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论 编辑记录
查看更多回答(2条)

报告相同问题?

问题事件

  • 系统已结题 3月5日
  • 已采纳回答 2月25日
  • 创建了问题 2月25日

悬赏问题

  • ¥15 微信公众平台自制会员卡可以通过收款码收款码收款进行自动积分吗
  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
  • ¥100 监控抖音用户作品更新可以微信公众号提醒
  • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
  • ¥70 2048小游戏毕设项目
  • ¥20 mysql架构,按照姓名分表
  • ¥15 MATLAB实现区间[a,b]上的Gauss-Legendre积分
  • ¥15 delphi webbrowser组件网页下拉菜单自动选择问题