首页 > 解决方案 > 找不到我得到的 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'

我试图寻找答案,但找不到任何东西。我确定我忘记了什么。

标签: python

解决方案


推荐阅读