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 
    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()

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

代码看着好像没有什么问题,看下是不是在python2中使用了python3的super()写法,检查下python版本呗

不知道你这个问题是否已经解决, 如果还没有解决的话:

如果你已经解决了该问题, 非常希望你能够分享一下解决方案, 写成博客, 将相关链接放在评论区, 以帮助更多的人 ^-^