我正在学习Python3。我坚持练习。我在下面的代码中找不到该问题,该问题给了我AttributeError
消息。
#child class of Users called Admin
class Admin(Users):
"""Initilize Users parent class attributes"""
def __init__(self, name, last, year, location):
super().__init__(name, last, year, location)
self.admin_privileges = Privileges()
#attribute class to child class Admin
class Privileges():
"""Initilize attributes"""
def __inti__(self, privileges=[]):
self.privileges_list = privileges
def show_privileges(self):
"""Displays admin privileges"""
print('As an admin you can: ')
if self.privileges_list:
for privilege in self.privileges_list:
print('-' + privilege)
else:
print("This account doesn't have privileges.")
admin = Admin('bob', 'chef', '1883', 'usa')
admin.greet_user()
admin.describe_user()
admin_priv = ['can add posts', 'can delete post', 'can ban user']
admin.admin_privileges.privileges = admin_priv
admin.admin_privileges.show_privileges()
以下是显示错误的输出:
User Bob's information:
First name: Bob
Last name: Chef
Birth year: 1883
Location: Usa
Login's: 0
As an admin you can:
Traceback (most recent call last):
File "user_class.py", line 84, in <module>
admin.admin_privileges.show_privileges()
File "user_class.py", line 71, in show_privileges
if self.privileges_list:
AttributeError: 'Privileges' object has no attribute 'privileges_list'
我尝试寻找答案,但找不到任何东西。我确定我忘了一些东西。