问题
I have pickled objects to a file in append mode but it only reads a single object. Here's the code. I don't know what I am doing wrong.
with open('notes.pkl', 'ab') as fileObject: #append
pickle.dump(obj, fileObject, pickle.HIGHEST_PROTOCOL)
with open('notes.pkl', 'rb') as input: #read
obj= pickle.load(input)
//perform tasks for each obj unpickled from the file
回答1:
You need to call pickle.load repeatedly until you hit end-of-file.
来源:https://stackoverflow.com/questions/36504887/how-do-i-unpickle-a-series-of-objects-from-a-file-in-python