pickle实例1-写文件

 

将字典写入文件( 序列化):

>>> 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()

 

 

 

 

 

分割线
感谢打赏
江西数库信息技术有限公司
YWSOS.COM 平台代运维解决方案
 评论
 发表评论
姓   名:

Powered by AKCMS