Esempio n. 1
0
    def get_students(self, path):
        """ Read the students information from path and add to self.students """
        try:
            #ask Student to add grades to the file

            for line in file_reader(path, 3, '\t', False):
                self.students[cwid] = Student(cwid, name, major)
        except ValueError as ex:
            print(ex)
Esempio n. 2
0
 def get_instructors(self, path):
     """ Read the students information and add to the instructor's file """
     try:
         for cwid, name, major in file_reader(path,
                                              3,
                                              sep='\t',
                                              header=False):
             self.students[cwid] = Student(cwid, name, dept)
     except ValueError as ex:
         print(ex)
Esempio n. 3
0
 def read_grades(self, path):
     """ read each grade and add it to the students and instructor """
     try:
         for student_cwid, course, grade, instructor_cwid in file_reader(
                 path, 3, '\t', False):
             if student_cwid in self.students:
                 self.students[student_cwid].add_course(course, grade)
         else:
             print(f"There was no grade found in '{instructor_cwid}'")
     except ValueError as ex:
         print(ex)
Esempio n. 4
0
 def get_grade(self, path):
     """ Read grades and add to both files """
     try:
         for student_cwid, course, grade, instructor_cwid in file_reader(
                 path, 4, '\t', False):
             if student_cwid in self_student:
                 self.students[student_cwid].add_grade(course, grade)
         else:
             print(f"No grade was found in the student's file")
     except ValueError as ex:
         print(ex)
         self.instructors[instructor_cwid].add_grade(course)
Esempio n. 5
0
 def read_instructors(self, path):
     """ read each student and add an instance of class Instructor to self.Instructors """
     for cwid, name, dept in file_reader(path, 3, '\t', False):
         self.instructors[cwid] = Instructor(cwid, name, dept)
Esempio n. 6
0
 def read_students(self, path):
     """ read each student and add an instance of class Student to self.students """
     for cwid, name, major in file_reader(path, 3, '\t', False):
         self.students[cwid] = Student(cwid, name, major)
Esempio n. 7
0
        """ Note that another student took a course with this instructor """
        self.courses[course] += 1

    def infor(self):
        return [self.cwid, self.name, sorted(self.courses.keys())]


class TestFile_reader(unittest.TestCase):
    def test_file_reader(self):
        path = r" C:/Users/user/AppData/Local/Programs/Python/Python38/HW08/txtfile.txt"

        self.assertTrue(Student, expected)


if __name__ == '__main__':
    path = r"C:/Users/user/AppData/Local/Programs/Python/Python38/HW08/txtfile.txt"
    print(list(file_reader(path, n=3, sep='|', header=False)))
    expected = {
        '11658': ['11658', 'Kelly, P', ['SSW 540']],
        '11461':
        ['11461', 'Wright, U', ['CS501', 'SYS 611', 'SYS 750', 'SYS 700']],
        '10115':
        ['10115', 'Wyatt, C', ['CS501', 'SSW564', 'SSW 567', 'SSW 687']],
        '10183': ['10183', 'Chapman, O', ['SSW 689']],
        '10103':
        ['10103', 'Baldwin, C', ['CS501', 'SSW564', 'SSW 567', 'SSW 687']],
        '10175': ['10175', 'Erickson, D', ['SSW 564', 'SSW 567', 'SSW 687']],
        '11714': ['11714', 'Morton, A', ['SYS 611', 'SYS 645']]
    }
    unittest.main(exit=False, verbosity=2)