python - 找不到我得到的 AttributeError 的来源
问题描述
我正在学习 Python 3。我坚持练习。我在下面的代码中找不到给我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'
我试图寻找答案,但找不到任何东西。我确定我忘记了什么。
解决方案
推荐阅读
- javascript - 如何使用javascript将值转换为数组
- python - 无法从 PyCharm 导入 TensorFlow
- r - 避免重新排序和分组重复的 x 值 ggplot (geom_point)
- python - 熊猫面板已弃用,
- reactjs - Reselect 相对于容器组件的优势
- php - Foreach 正在跳过一些字段
- c# - 当涉及到抽象类时,在 C# 中正确分配适当的修饰符
- regex - 用于匹配子字符串但不包含单词的正则表达式(单词边界问题)
- tabs - ActiveAdmin 设置选项卡处于活动状态
- javascript - 我正在尝试匹配数字值的字段输入,第一个字符必须是数字(1-9),其余任何数字