Python3.1之pickle

Python3.1把pickle cPickle合并了。调用的时候 直接import pickle as p 就可以了。

 

pickle就是python中序列化工具,可以序列化各种格式数据,甚至包括自己定义的。

 

简单的demo如下:

import pickle as cp

shoplistfile ='shoplist.data'
shoplist=['apple','pear','carrot']

f = open(shoplistfile,'wb')
cp.dump(shoplist,f)
f.close()

del shoplist

f=open(shoplistfile,'rb')
storedlist=cp.load(f)
print(storedlist)

 

执行结果如下:

['apple', 'pear', 'carrot']

你可能感兴趣的:(apple,python,F#)