0
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)

the teacherfunc main() function is a function that allows the user to view data but is not the problem. it gives an attribute error saying that the class Teacher does not have an attribute named __user, but it quite obviously isn't. I would be very grateful if you could help. thanks.

vaultah
  • 44,105
  • 12
  • 114
  • 143
  • See the duplicate; class attributes with a double-underscore are *mangled* (altered by adding in the class name) to avoid collisions with attributes with the same name in subclasses. – Martijn Pieters Feb 05 '16 at 16:01
  • 1
    You also want to avoid getters and setters; Python is not Java, you don't need private attributes and you don't need to worry about having to convert to a `property` object later on. – Martijn Pieters Feb 05 '16 at 16:01
  • @MartijnPieters yeah, I had only just learnt about classes and OOP, and now I look at this code and cringe – Bradley Hastings Aug 02 '17 at 15:45

0 Answers0