from student import * def readStudents(fname): """ fname is the file name, tries to read the information from the file and generate a list of students records, returns the list of student records if successful, retuns False otherwise """ try: source = open(fname) except: # in case if file cannot be opened, terminate the function, return False return False studentsRecords = {} # empty dictionary student = source.readline() # read the first line from the file pos = student.find(" ") #print(student[:pos],",",student[pos+1:]) # create a student record and add it to the dictionary of students' records # key is the student's id studentsRecords[int(student[:pos])]=makeStudent(student[pos+1:]) for line in source: # read the rest of the lines from the file #print("read:",line) pos = line.find(" ") studentsRecords[int(line[:pos])]=makeStudent(line[pos+1:]) source.close() print("{0} student records are read".format(len(studentsRecords))) return studentsRecords def main(): # get the file name fname = input("Enter the name of input file:") records = readStudents(fname) if records != False: print("Student's list:") for key in records: print("{0}: {1}".format(key,records[key].getName())) else: print("something happened. The records were not read") main()