1. 程式人生 > >Python pickle序列化模組

Python pickle序列化模組

import pickle
a = {'name':'Tom','age':22}
with open('text.txt','wb') as file:
    #這裡寫入檔案為二進位制形式,讀也是二進位制形式
    pickle.dump(a,file)
#text.txt 存在當前目錄下
with open('text.txt','rb') as file2:
    b = pickle.load(file2)
print(b)
#這裡b與a有相同的內容