当前位置: 首页>>代码示例>>Python>>正文


Python Student.get_student_name方法代码示例

本文整理汇总了Python中student.Student.get_student_name方法的典型用法代码示例。如果您正苦于以下问题:Python Student.get_student_name方法的具体用法?Python Student.get_student_name怎么用?Python Student.get_student_name使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在student.Student的用法示例。


在下文中一共展示了Student.get_student_name方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: load_student_data

# 需要导入模块: from student import Student [as 别名]
# 或者: from student.Student import get_student_name [as 别名]
def load_student_data(filename):
    """A function that reads data from a CSV file and stores it into objects.

    Args:
       filename: Name of the file

    Returns:
        A dictionary of Grade objects.

    """

    grades_dict = {}

    csv_f = open(filename, 'r')
    i = 0
    for line in csv_f:
        # print "line no:", i, "=", line
        if i > 0:
            # We don't need to read the header, so
            # we do not read line 0
            line_list = []
            line_list = line.split(',')

            grade_number = int(line_list[0])
            # Only create a grade object if it doesn't already exist
            if grade_number in grades_dict:
                grade_temp = grades_dict[grade_number]
            else:
                grade_temp = Grade(grade_number)

            sections_dict = grade_temp.get_sections()
            section_number = int(line_list[1])
            # Only create a section object if it doesn't already exist
            # in that grade
            if section_number in sections_dict:
                section_temp = sections_dict[section_number]
            else:
                section_temp = Section(section_number)

            students_dict = section_temp.get_students()
            student_name = line_list[2]
            # Only create a student object if it doesn't already exist
            # in that section
            if student_name in students_dict:
                student_temp = students_dict[student_name]
            else:
                student_temp = Student(student_name)

            subjects_dict = student_temp.get_subjects()
            subject_name = line_list[3]
            # Only create a subjects object if it doesn't already exist
            # in that student object
            if subject_name in subjects_dict:
                subject_temp = subjects_dict[subject_name]
            else:
                subject_temp = Subject(subject_name)

            tests_dict = subject_temp.get_tests()
            test_obj = Test(line_list[4], int(line_list[5]), int(line_list[6]),
                            line_list[7], line_list[8])

            tests_dict[test_obj.get_test_name()] = test_obj
            subject_temp.set_tests(tests_dict)

            subjects_dict[subject_temp.get_subject_name()] = subject_temp
            student_temp.set_subjects(subjects_dict)

            students_dict[student_temp.get_student_name()] = student_temp
            section_temp.set_students(students_dict)

            sections_dict[section_temp.get_section_number()] = section_temp
            grade_temp.set_sections(sections_dict)

            grades_dict[grade_temp.get_grade_number()] = grade_temp
        # variable i tracks line numbers read
        i = i + 1
    csv_f.close()
    return grades_dict
开发者ID:saulatmajid,项目名称:Final_Project_Revised,代码行数:80,代码来源:final_project.py


注:本文中的student.Student.get_student_name方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。