标签:blog io 使用 ar for 文件 数据 div 2014
import pickle class Bird(object): have_feather = True way_of_reproduction = 'egg' summer = Bird() pickleString = pickle.dumps(summer) # serialize object
import pickle class Bird(object): have_feather = True way_of_reproduction = 'egg' summer = Bird() fileName = 'save.pkl' with open(fileName, 'w') as f: # open file with write-mode pickleString = pickle.dump(summer, f) # serialize and save object对象summer存储在文件save.pkl
import pickle # define the class before unpickle class Bird(object): have_feather = True way_of_reproduction = 'egg' fileName = 'save.pkl' with open(fileName, 'r') as f: summer = pickle.load(f) # read file and build object
import cPickle as pickle就不须要再做不论什么修改了。
Python学习笔记12:标准库之对象序列化(pickle包,cPickle包)
标签:blog io 使用 ar for 文件 数据 div 2014
原文地址:http://www.cnblogs.com/mengfanrong/p/4029611.html