import pickle as p
class PickleTest:
def __init__(self,o,filename):
if not 0:
self.obj=o
self.filename=filename
def dump(self):
print 'save data ',self.obj,' >> ',self.filename
f = file(filename,'w')
p.dump(self.obj,f)
def load(self):
f = file(self.filename)
s = p.load(f)
print 'load data from ',self.filename,' >>',s
return s
if __name__=='__main__':
filename = 'test.data'
obj = {'p1':[0,1,2,3],'p2':(1,2,3),'p3':{'1':1,'2':2},'p4':'str'}
test = PickleTest(obj,filename)
test.dump()
test.load()