1 pickle
什么对象都可以存储
# 写
with open("lang.data", 'wb') as f:
pickle.dump(lang, f)
# 读
with open("lang.data", "rb") as f:
lang = pickle.load(f)
2 json
ensure_ascii属性用来控制显示汉字,这样一般
# 写
with open("lang.json", 'w', encoding='utf8') as f:
f.write(json.dumps(lang.index2word, ensure_ascii=False) + '\n')
# 读
f.loads()