pickle模塊的運用
pickle提供了一個簡單的持久化功能??梢詫ο笠晕募男问酱娣旁诖疟P上。
python的pickle模塊實現(xiàn)了基本的數(shù)據(jù)序列和反序列化
通過pickle模塊的序列化操作我們能夠將程序中運行的對象信息保存到文件中去,永久存儲
-
通過pickle模塊的反序列化操作,我們能夠從文件中創(chuàng)建上一次程序保存的對象。
pickle.dump() / pickle.load()
import pickle
data = {'a':1, 'b': 2}
# 寫入
with open('data.pkl', 'wb') as f:
pickle.dump(data, f)
# 讀取
with open('data.pkl', 'rb') as f1:
print(pickle.load(f1))
更多學習鏈接:https://blog.csdn.net/sxingming/article/details/52164249
https://blog.csdn.net/coffee_cream/article/details/51754484
https://docs.python.org/zh-cn/3/library/pickle.html#module-pickle