本文整理汇总了Python中student.Student.addCourse方法的典型用法代码示例。如果您正苦于以下问题:Python Student.addCourse方法的具体用法?Python Student.addCourse怎么用?Python Student.addCourse使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类student.Student
的用法示例。
在下文中一共展示了Student.addCourse方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
# 需要导入模块: from student import Student [as 别名]
# 或者: from student.Student import addCourse [as 别名]
def main():
outFile = open("students.dat", "wb")
course1 = Course("CSC 157-050", "B", 4)
course2 = Course("EGL 101-001", "C", 3)
course3 = Course("PHY 201-0C1", "A", 5)
course4 = Course("MAT 251-002", "B", 5)
pickle.dump(course1, outFile)
pickle.dump(course2, outFile)
pickle.dump(course3, outFile)
pickle.dump(course4, outFile)
student1 = Student("Jim Bob")
student1.addCourse(course1)
student1.addCourse(course2)
student1.addCourse(course3)
student1.addCourse(course4)
print(student1)
pickle.dump(student1, outFile)
print("Student data was written to students.dat")
outFile.close()
end_of_file = False
inFile = open("students.dat", "rb")
student_info = []
print("\nNow reading students.dat")
while not end_of_file:
try:
info = pickle.load(inFile)
#add info to a list
student_info.append(str(info)) #use the str method to convert the course into a string
except EOFError:
end_of_file = True
inFile.close()
print(student_info)
#add objects to a list
dict_courses = {"First": course1, "Second": course2, "Third": course3, "Fourth": course4}
for label, c in dict_courses.items():
print(label, c)
not_found = True
checks = [False, False, False, False]
while not_found:
for label, c in dict_courses.items():
if label == "First":
checks[0] = "First"
elif label == "Second":
checks[1] = "Second"
elif label == "Third":
checks[2] = "Third"
elif label == "Fourth":
checks[3] = "Fourth"
if checks[0] != False and checks[1] != False and checks[2] != False and checks[3] != False:
print(dict_courses[checks[0]])
print(dict_courses[checks[1]])
print(dict_courses[checks[2]])
print(dict_courses[checks[3]])
not_found = False
示例2: TestSpec
# 需要导入模块: from student import Student [as 别名]
# 或者: from student.Student import addCourse [as 别名]
class TestSpec(unittest.TestCase):
def setUp(self):
self.s = Student()
def test_getCourses_returns_empty_default(self):
courses = self.s.getCourses()
self.assertListEqual([], courses)
def test_addCourse_requires_Course_instance(self):
course = Course()
self.s.addCourse(course)
self.assertEquals([course], self.s.getCourses())
with self.assertRaises(ValueError):
self.s.addCourse('not an instance')