将字典写入文件( 序列化):
>>> import pickle
>>> account_info={
... '134134134':['alex31234',15000,15000]
... }
>>> f=file('account.pkl','wb')
>>> pickle.dump(account_info,f)
>>> account_info['134134134'][0]='Fiona'
>>> pickle.dump(account_info,f)
>>> f.close()
[root@node110 function]# cat account.pkl
(dp0
S'134134134'
p1
(lp2
S'alex31234'
p3
aI15000
aI15000
as.[root@node110 function]#
将pickle读入(反序列化):
>>> import pickle
>>> pkl_file=open('account.pkl','rb')
>>> account_list=pickle.load(pkl_file)
>>> account_list2=pickle.load(pkl_file)
>>> account_list
{'134134134': ['alex31234', 15000, 15000]}
>>> pkl_file.close()