美好的一天!我对python字典和json有疑问!在一个文件中我创建了具有以下结构的json字典:
{"face_1": {"face_rect": "(127, 68, 177, 177)", "Age": 1, "Gender": 1}}
因为它使用这个代码(i - 面的数量,(x,y,w,h) - 坐标的矩形。):
for i, (x, y, w, h) in enumerate(faces):
face = dict()
face["face_{}".format(i + 1)] = {"face_rect": str((x, y, w, h)), "Age": 1, "Gender": 1}
with open('face.json', 'a') as fp:
data_to_write = json.dumps(face)
fp.write(data_to_write + '\n')
在此之前,一切都很棒。我的问题 - 如何在另一个py文件和CHANGE值'Age','Gender'打开这个字典(face.json)并保存它? 感谢您的时间!
答案 0 :(得分:1)