import pickle
data = ["this", "is", "your", "data"]
indices = [] # keep the index
with open("file_name.p", "wb") as f:
for value in data:
indices.append(f.tell())
pickle.dump(value, f)
# you may want to store `indices` to files
# and read it in again
new_data = []
with open("file_name.p", "rb") as f:
for ap in indices[::-1]:
f.seek(ap)
new_data.append(pickle.load(f))
print(new_data)
您可以保留项目的索引,并以新的顺序读取它们:
相关问题 更多 >
编程相关推荐