pickle序列化

 

 

 

#从内存写入到硬盘:
import pickle
dic={'a':'111','b':'222'}
f=open('c:\\pic.pkl','wb')
pickle.dump(dic,f)
f.close()  #每dump一次,务必要关闭文件,如果dump多次后,会load出来新旧数据

#从硬盘读取到内存
p=open('c:\\pic.pkl','rb')
pp=pickle.load(p)
print(pp)
p.close()

#dumps--loads:Return the pickled representation of the object as a bytes object, instead of writing it to a file.

pickle.loads(pickle.dumps(dic))

 

posted on 2016-04-23 19:53  momingliu11  阅读(226)  评论(0编辑  收藏  举报