1、持久化 - pickle
- 持久化(序列化,落地):把程序运行中的信息保存到磁盘上
- 反序列化:序列化的逆过程
- pickle:
-
python提供的序列化模块
-
pickle.dump:序列化
-
pickle.load:反序列化
#序列化 import pickle age = 12 with open(r'F:\FileOperation\test01.txt','wb') as f: pickle.dump(age,f) #反序列化 with open(r'F:\FileOperation\test01.txt','rb') as f: age = pickle.load(f) print(age)
-
复杂一点的案例
import pickle a = [19,'Yangshuo','I love WangChen',[178,66]] with open(r'F:\FileOperation\test01.txt','wb') as f: a = pickle.dump(a,f)
import pickle with open(r'F:\FileOperation\test01.txt','rb') as f: a = pickle
-