首页 > 编程语言 > 详细

Learn Python From 'Head First Python' [3](2) : Pickle

时间:2014-09-17 23:13:52      阅读:409      评论:0      收藏:0      [点我收藏+]

1.the use of ‘with open... as ...‘

2.the use of pickle(dump and load)

for Step1:

the ‘with open ... as...‘ is the short format of ‘try...except...finally‘

 

for Step2:

you can store a list with pickle.dump() and get the content again with pickle.load()

 1 >>> import pickle
 2 >>> with open(test.pickle,wb) as data:
 3     pickle.dump([a,2,et],data)
 4 
 5     
 6 >>> with open(test.pickle,rb) as readFile:
 7     the_list = pickle.load(readFile)
 8 
 9     
10 >>> the_list
11 [a, 2, et]
12 >>> 

 

when use this method, you should be care with the encoding of file, like ‘wb‘,‘rb‘

Learn Python From 'Head First Python' [3](2) : Pickle

原文:http://www.cnblogs.com/zhuojiniao/p/3978212.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!