예제 #1
0
 def __init__(self, filename):
     """
     Constructor method
     Opens the file and loads the entries in memory
     filename is a string, the path to the file used for storage
     O(n)
     """
     ClientList.__init__(self)
     self.__filename = filename
     try:
         self.__clientFile = open(filename, "r")
     except IOError:
         # File does not exist. Create it.
         self.__clientFile = open(filename, "w")
         self.__clientFile.close()
         self.__clientFile = open(filename, "r")
     line = "Nonempty String"
     while line != "":
         line = self.__clientFile.readline()
         if line == "" or line == "\n":
             break
         details = line.split("|")
         client = Client(details[0], details[1])
         if details[2] != "":
             borrowedBooks = details[2].split(";")
             for borrowedBook in borrowedBooks:
                 if borrowedBook != "":
                     bookDetails = borrowedBook.split()
                     book = Book(bookDetails[0], bookDetails[1],
                                 bookDetails[2])
                     client.addBorrowedBook(book)
         client.setActivity(int(details[3]))
         self.clientList.append(client)
     self.__clientFile.close()
예제 #2
0
 def __init__(self, filename):
     """
     Constructor method
     Opens the file and loads the entries in memory
     filename is a string, the path to the file used for storage
     O(n)
     """
     ClientList.__init__(self)
     self.__filename = filename
     try:
         self.__clientFile = open(filename, "r")
     except IOError:
         # File does not exist. Create it.
         self.__clientFile = open(filename, "w")
         self.__clientFile.close()
         self.__clientFile = open(filename, "r")
     line = "Nonempty String"
     while line != "":
         line = self.__clientFile.readline()
         if line == "" or line == "\n":
             break
         details = line.split("|")
         client = Client(details[0], details[1])
         if details[2] != "":
             borrowedBooks = details[2].split(";")
             for borrowedBook in borrowedBooks:
                 if borrowedBook != "":
                     bookDetails = borrowedBook.split()
                     book = Book(bookDetails[0], bookDetails[1], bookDetails[2])
                     client.addBorrowedBook(book)
         client.setActivity(int(details[3]))
         self.clientList.append(client)
     self.__clientFile.close()