def _get_instructors(self, path): """ read the instructors and populate self._instructors """ for cwid, name, dept in file_reading_gen(path, 3, sep='\t', header=False): self._instructors[cwid] = Instructor(cwid, name, dept)
def _get_students(self, path): """ read the students and populate self._students """ for cwid, name, major in file_reading_gen(path, 3, sep='\t', header=False): self._students[cwid] = Student(cwid, name, major)
def test_file_reading_gen(self): """ test_file_reading_gen """ path = '/Users/LSM/Desktop/test2.txt' expect = (('123', 'Jin He', 'Computer Science'), ('234', 'Nanda Koka', 'Software Engineering'), \ ('345', 'Benji Cai', 'Software Engineering')) result = tuple(file_reading_gen(path, 3, sep='|', header=True)) self.assertEqual(result, expect)
def _get_students(self, path): """ read the students and populate self._students """ for cwid, name, major_name in file_reading_gen(path, 3, sep=';', header=True): if major_name not in self._majors: print(f"Student {cwid} '{name}' has unknown major '{major}'") else: self._students[cwid] = Student(cwid, name, major_name, self._majors[major_name])
def _get_majors(self, path): """ get majors """ for dept, flag, course in file_reading_gen(path, 3, sep='\t', header=True): if dept not in self._majors.keys(): self._majors[dept] = Major(dept) self._majors[dept].add_course(flag, course)
def _get_grades(self, path): """ get grades """ for student_cwid, course, grade, instructor_cwid in file_reading_gen(path, 4, sep='|', header=True): if student_cwid in self._students: self._students[student_cwid].add_course(course, grade) # tell the student about a course else: print(f'Found grade for unknown student {student_cwid}') if instructor_cwid in self._instructors: self._instructors[instructor_cwid].add_student(course) # tell the instructor about a course/student else: print(f'Found course for unknown instructor {instructor_cwid}')