序列化:把内存中的变量变成可存储或可传输的过程。
在python中提供了cPickle和Pickle,cPickle使用C写的效率高。
pickle.dump(d,f) 序列化
pickle.load(f) 反序列化
如下代码:
try:
import cPickle as pickle
except ImportError:
import pickle
# # 序列化
# with open(r'1.txt','wb') as ff:
# d = dict(url='1111', title='2222', content='33333')
# pickle.dump(d,ff)
with open(r'1.txt','rb') as ff:
d = pickle.load(ff)
print(d)