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}