def readReservationsFile(file_name): """Reads a file with a list of reservations into a collection. Requires: file_name is a string with the name of a .txt file containing a list of reservations organized as in the examples provided in the general specification (omitted here for the sake of readability). Ensures: list L of lists, where each list corresponds to a reservation listed in file name with file_name and its elements are the elements belonging to that reservation in the order provided in the lines of the file. in this list L: clients reserving a service with an earlier starting time have priority over the ones with later starting times; lexicographic order of clients's names decides eventual ties. """ inFile = removeHeader(open(file_name, "r")) reservationsList = [] for line in inFile: reservationsList.append(line.rstrip().split(", ")) return reservationsList
def readServicesFile(file_name): """Reads a file with a list of services into a collection. Requires: file_name is str with the name of a .txt file containing a list of services organized as in the examples provided in the general specification (omitted here for the sake of readability). Ensures: list L of lists, where each list corresponds to a service listed in file with name file_name and its elements are the elements belonging to that service in the order provided in the lines of the file. in this list L: drivers terminating their services earlier have priority over the ones terminating later; lexicographic order of drivers's names decides eventual ties in each case above. """ inFile = removeHeader(open(file_name, "r")) servicesList = [] for line in inFile: servicesList.append(line.rstrip().split(", ")) return servicesList
def readDriversFile(file_name): """Reads a file with a list of drivers into a collection. Requires: file_name is str with the name of a .txt file containing a list of drivers organized as in the examples provided in the general specification (omitted here for the sake of readability). Ensures: dict where each item corresponds to a driver listed in file with name file_name, a key is the string with the name of a driver, and a value is the list with the other elements belonging to that driver, in the order provided in the lines of the file. """ inFile = removeHeader(open(file_name, "r")) driversDict = {} for line in inFile: driverData = line.rstrip().split(", ") driverName = driverData.pop(INDEXDriverName) driversDict[driverName] = driverData return driversDict
def readVehiclesFile(file_name): """Reads a file with a list of vehicles into a collection. Requires: file_name is str with the name of a .txt file containing a list of vehicles organized as in the examples provided in the general specification (omitted here for the sake of readability). Ensures: dict where each item corresponds to a vehicle listed in file with name file_name, a key is the string with the plate of a vehicle, and a value is the list with the other elements belonging to that vehicle, in the order provided in the lines of the file. """ inFile = removeHeader(open(file_name, "r")) vehiclesDict = {} for line in inFile: vehicleData = line.rstrip().split(", ") vehiclePlate = vehicleData.pop(INDEXVehiclePlateInDict) vehiclesDict[vehiclePlate] = vehicleData return vehiclesDict