dict保存成文件(对象序列化)
d = dict(name=‘TSQ‘, age=18) import pickle with open("dict.file", "wb") as f: pickle.dump(d, f)
文件读取成dict(文件反序列化)
d = {} import pickle with open("dict.file", "rb") as f: d = pickle.load(f) print(d)
print(d)的结果是
{‘name‘: ‘TSQ‘, ‘age‘: 18}
原文地址:https://www.cnblogs.com/taoshiqian/p/9771786.html
时间: 2024-11-09 17:09:44