您的位置:首页 > 编程语言 > Python开发

Python 通过pickle标准库加载和保存数据对象

2015-09-29 10:40 555 查看
import pickle

with open('mydata.pickle','wb') as mysavedata:
pickle.dump([1,2,'three'], mysavedata)
with open('mydata.pickle','rb') as myrestoredata:
a_list=pickle.load(myrestoredata)
print(a_list)


import nester and print

import pickle
import nester

new_man=[ ]
try:
with open('mydata.pickle','rb') as man_file:
new_man=pickle.load(man_file)
except IOError as err:
print('file error' + str(err))
except pickle.PickleError as perr:
print('pickling error' + str(perr))

nester.print_lol(new_man)
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: