首页 > 代码库 > Learn Python From 'Head First Python' [3](2) : Pickle
Learn Python From 'Head First Python' [3](2) : Pickle
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_list11 [‘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
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。