求解答
报错如下:
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()