码迷,mamicode.com
首页 > 编程语言 > 详细

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

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

标签:style   blog   color   ar   for   div   sp   log   on   

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

标签:style   blog   color   ar   for   div   sp   log   on   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!