Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class User:
- def __init__(self, name, lastname, login, password):
- self.name = name
- self.lastname = lastname
- self.login = login
- self.password = password
- def welcome(self):
- print("Welcome {}{}".format(self.name, self.lastname))
- class Admin(User):
- def __init__(self,name="Mateusz", lastname="Grabarczyk", login="admin", password="admin"):
- super().__init__(name, lastname, login, password)
- def welcome(self):
- print("Welcome {} {}, our dear Admin!".format(self.name, self.lastname))
- class Student(User):
- def __init__(self, id, name, lastname, login, password):
- super().__init__(name, lastname, login, password)
- self.issued_books = []
- self.id = id
- def welcome(self):
- print("Welcome {} {}, right now you have {} issued books.".format(self.name, self.lastname, len(self.issued_books)))
- class UserDatabase():
- student_list = []
- def LoadUsers(self):
- with open("users.txt") as f:
- for line in f:
- data = line.strip().split(',')
- try:
- student = Student(data[0], data[1], data[2], data[3], data[4])
- if len(data) > 5:
- for i in range(5, len(data)):
- student.issued_books.append(data[i])
- self.student_list.append(student)
- except:
- pass
- def overwriteUsersTxt(self):
- with open("users.txt", "w") as f:
- for s in self.student_list:
- f.write("{},{},{},{},{}".format(s.id, s.name, s.lastname, s.login, s.password))
- f.write("\n")
- def print_users(self):
- for user in self.student_list:
- print("{} - {} {}".format(user.id, user.name, user.lastname))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement