Python:如何从包含字典的文件中循环

python的新手,尝试读取具有多行的文件,每行代表一个字典,它是csv文件,其文本如下

{
   "Final": {
      "Final grade": "O",
      "Class 1": {
         "Student_4": {
            "Subject S0": {
               "Grade": "A"
            }
         },
         "Student_1": {
            "Subject S0": {
               "Grade": "B"
            }
         },
         "Student_0": {
            "Subject S0": {
               "Grade": "A"
            }
         },
         "Student_3": {
            "Subject S0": {
               "Grade": "A"
            }
         },
         "Student_2": {
            "Subject S0": {
               "Grade": "A"
            }
         },
         "Grade": "A",
      },
      "Class 2": {
         "Student_2": {},
         "Student_1": {
            "Subject S0": {
               "Grade": "B"
            }
         },
         "Student_0": {
            "Subject S0": {
               "Grade": "B"
            }
         },
         "Student_3": {
            "Subject S0": {
               "Grade": "B"
            }
         },
         "Student_4": {
            "Subject S0": {
               "Grade": "B"
            }
         },
         "Grade": "B",

      }
   }
}

我需要找到每个学科的每个学生的成绩并写入新文件。

我该如何实现?另外,如果特定班级的学生有2个或更多科目,我该如何编写通用代码来运行。

评论