Python_pickle
pickle是一个可以将任意一个对象存储在硬盘文件中的工具。
更新:Python3中用法变了: https://www.cnblogs.com/fmgao-technology/p/9078918.html
ref:https://docs.python.org/2/library/pickle.html
常用的用法就两个。。。dump(写入文件)和load(从文件中读)
demo:
1 __author__ = 'IBM' 2 import pickle 3 4 fp="D:/pycharmprojects/pickle_demo/r.pkl" 5 6 data="233333_woshihanbazi" 7 with open(fp,"wb") as f: 8 pickle.dump(data,f) 9 10 with open(fp,"rb") as f: 11 dat=pickle.load(f) 12 print(dat)
Output:
233333_woshihanbazi
posted on 2016-02-10 15:11 Pentium.Labs 阅读(144) 评论(0) 编辑 收藏 举报