Advertisement
MateuszGrabarczyk

UserDB

Mar 29th, 2022
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.98 KB | None | 0 0
  1. from LibrarySystem.scr.Student import *
  2.  
  3.  
  4. class UserDatabase:
  5. student_list = []
  6.  
  7. def readFromUserTxt(self):
  8. with open("users.txt", "r") as f:
  9. for line in f:
  10. data = line.strip().split(';')
  11. try:
  12. student = Student(data[0], data[1], data[2], data[3], data[4])
  13. if len(data) > 5:
  14. for i in range(5, len(data)):
  15. student.issued_books.append(data[i])
  16. self.student_list.append(student)
  17. except:
  18. pass
  19.  
  20. def writeToUserTxt(self):
  21. with open("users.txt", "w") as f:
  22. for s in self.student_list:
  23. f.write("{};{};{};{};{}".format(s.id, s.name, s.lastname, s.login, s.password))
  24. f.write("\n")
  25.  
  26. def print_users(self):
  27. for user in self.student_list:
  28. print("{} - {} {}".format(user.id, user.name, user.lastname))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement