python如何将字典格式写入文本

目前暂时只看到写入Json格式的,json格式也可以使用,或者说反过来也可以直接提取dict

import json
dict_1={'val_loss':handle_loss,'val_acc':handle_acc,'val_precision':handle_precision,'val_recall':handle_recall,'val_fmeasure':handle_fmeasure,'val_top_3_categorical_accuracy':handle_top_3_categorical_accuracy}

jsObj = json.dumps(dict_1)

fileObject = open(r'D:\code_python\matrix_dic2.json', 'w')

fileObject.write(jsObj)

fileObject.close()

你可能感兴趣的:(python,基础教学,python基础,python字典)