我在追加模式下将文件腌制到文件中,但它只读取一个对象。这是代码。我不知道我做错了什么。
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
答案 0 :(得分:-1)
您需要反复调用pickle.load
,直到您点击文件结尾。