Python 中文dict读写txt

将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() 

你可能感兴趣的:(Python 中文dict读写txt)