def _get_majors(self, path): """ Read majors files and assign the course to the majors Handle exceptions in the calling function. """ for major, flag, course in rf.file_reading_gen(path, 3, sep='\t', header=True): if major not in self._majors: self._majors[major] = Major(major) self._majors[major].add_course(course, flag)
def _get_students(self, path): ''' Read students from path and add to the self.students Allow exceptions from reading the file to flow back to the caller. ''' for cwid, name, major in rf.file_reading_gen(path, 3, sep=';', header=True): if major not in self._majors: print(f"Student {cwid} '{name}' has unknown major '{major}'") else: self._students[cwid] = Student(cwid, name, self._majors[major])
def _get_grades(self, path): ''' Read grades from path and add to the self.instructors Allow exceptions from reading the file to flow back to the caller. ''' for student_cwid, course, grade, instructor_cwid in rf.file_reading_gen(path, 4, sep='|', header=True): if student_cwid in self._students: self._students[student_cwid].add_course(course, grade) else: print(f"Found grade for unknown student '{student_cwid}") if instructor_cwid in self._instructors: self._instructors[instructor_cwid].add_student(course) else: print(f"Found grade for unknown instructor '{instructor_cwid}")
def _get_instructors(self, path): ''' Read instructors from path and add to the self.instructors Allow exceptions from reading the file to flow back to the caller. ''' for cwid, name, dept in rf.file_reading_gen(path, 3, sep='|', header=True): self._instructors[cwid] = Instructor(cwid, name, dept)