This repository has been archived on 2024-06-23. You can view files and clone it, but cannot push or open issues or pull requests.
mathdeptv2/工具/导入关联题目.py

21 lines
679 B
Python

import json
"""编辑完成保存关闭后运行这个代码块"""
with open(r"../题库0.3/Problems.json","r",encoding = "utf8") as f:
database = f.read()
pro_dict = json.loads(database)
with open(r"临时文件/problem_edit.json","r",encoding="u8") as f:
datanew = f.read()
new_pro = json.loads(datanew)
for id in new_pro:
pro_dict[id] = new_pro[id].copy()
#按id排序生成字典
sorted_dict_id = sorted(pro_dict)
sorted_dict = {}
for id in sorted_dict_id:
sorted_dict[id] = pro_dict[id]
#将排序后的字典转为json
with open(r"../题库0.3/Problems.json","w",encoding = "utf8") as f:
f.write(json.dumps(sorted_dict,indent = 4,ensure_ascii=False))