pickle实现实例化对象的存与读
import pickle
class Mypickle:
def __init__(self,path):
self.file = path
def dump(self,obj):
with open(self.file, 'ab') as f:
pickle.dump(obj, f)
def load(self):
with open(self.file,'rb') as f:
while True:
try:
yield pickle.load(f)
except EOFError:
break
a=A('cat',1)
s=Mypickle('file')
s.dump(a)
s.load()