为什么我会收到此属性错误?

时间:2016-02-05 15:58:26

标签: python python-3.x

import teacherfunc


class Teacher:
    __name = ""
    __user = ""
    __class = ""
    __passwd = ""
    def __init__(self, name, user, clas, passwd):
        self.__name = name
        self.__user = user
        self.__class = clas
        self.__passwd = passwd

    def set_name(self, name):
        self.__name = name
    def get_name(self):
        return self.__name

    def set_user(self, user):
        self.__user = user
    def get_user(self):
        return self.__user

    def set_class(self, clas):
        self.__class = clas
    def get_class(self):
        return self.__class

    def set_passwd(self,passwd):
        self.__passwd = passwd
    def get_passwd(self):
        return self.__passwd        

mrhall = Teacher("Stuart Hall", "halls", "Class_A", "passwd")
mrkasanda = Teacher("Kasanda", "kasandam", "Class_B", "passwd")
mrbeasley = Teacher("Bradley Beasley", "beasleyb", "Class_C", "passwd")



userinp = input("What teacher are you: ")

for field in [mrhall, mrkasanda, mrbeasley]:

    if field.__user == userinp.lower():
        usr = field

print("Welcome", usr.__passwd)
passinp = input("Enter your password to get class scores: ")
while passinp != usr.__passwd:
    passinp = input("Enter your password to get class scores: ")

teacherfunc.main(usr.__user)

teacherfunc main()函数是一个允许用户查看数据但不是问题的函数。它给出了一个属性错误,说教师类没有名为__user的属性,但很明显不是。 如果你能提供帮助,我将非常感激。 感谢。

0 个答案:

没有答案