"""
[
{
"user_id": 1,
"exer_id": 1,
"score": 1.0,
"knowledge_code": [
1,
10
]
},
]
"""
import pickle
import json
path1 = "C:/Users/students_answers.pickle"
path2 = "C:/Users/questions_tags.pickle"
#得到习题-知识点字典
with open(path1, 'rb') as f:
students_answers = pickle.load(f)
with open(path2, 'rb') as f:
questions_tags = pickle.load(f)
# key_class_list = []
# with open('data/log_data.json', encoding='utf8') as i_f:
# stus = json.load(i_f)
statics = []
for s, dou_list in students_answers.items():
for response in dou_list:
record = {}
record['user_id'] = s
record['exer_id'] = response[0]
record['score'] = response[1]
record['knowledge_code'] = questions_tags[response[0]]
statics.append(record)
with open("C:/Users/log_data.json", 'w', encoding='utf8') as f:
json.dump(statics, f, indent=4)
print(len(statics))
将数据写成JSON格式,indent使用
最新推荐文章于 2023-02-15 15:43:31 发布