将dict 写入txt
import json
js = json.dumps(data,ensure_ascii=False)
file = open('test.txt', 'w')
file.write(js)
file.close()
data: dict字典数据
从txt读取dict
import json
file = open('test.txt', 'r')
js = file.read()
dic = json.loads(js)
print(dic)
file.close()
网友评论