cPickle and pickle
Posted XinZhou_Annie
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了cPickle and pickle相关的知识,希望对你有一定的参考价值。
import cPickle as p #import pickle as p AddressListfile = ‘AddressList.data‘ # the name of the file where we store the information AddressList = {‘Xiaopeng Yang‘: (18000001219, ‘[email protected]‘)} # Write to the file f = file(AddressListfile, ‘w‘) c = p.dump(AddressList, f) #dump the object to a file f.close() del AddressList # remove the AddressList #Read back from the storage d = file(AddressListfile) shoredlist = p.load(d) print shoredlist
Output
================= RESTART: /Users/zhouxin/Desktop/cPickle.py =================
{‘Xiaopeng Yang‘: (18000001219L, ‘[email protected]‘)}
>>>
It also creates AddressList.data.
About .data document:
data是数据保存的备份类文件。里面存放的是加密后的数据文件,如模型、贴图、源程序代码等。data文件打开的方式是不确定的,如果是:
1、数据文件, 可以用txt或word直接打开
2、vcd格式的影音文件,可以用meidaplayer打开!
About pickle :
you can store any Python object in a file and then get it back later intact. This is called storing the object persistently.
Use the cPickle module to store the objects persistently on your hard disk.
以上是关于cPickle and pickle的主要内容,如果未能解决你的问题,请参考以下文章
python3中的Pickle vs cPickle(?)[重复]