I'm trying to loop through every element in a pickled dat file. The idea is to pickle a list with a name and a score. I'm just trying to load every element without having to manually load each one. I figured I could use a while loop, but I'm not quite sure how to set it up. I've tried to look up more info on pickling, but I can't find much to help. I thought I could use some type of check to see if the dat file still contains elements in it and stop the loop once it doesn't, but I'm not sure that would even work. I have it set up to load the first element, I just can't figure the loop out.
Any help would be greatly appreciated.
def writeScoreList(appendList):
f = open("scores.dat","ab")
pickle.dump(appendList,f)
f.close()
print("\nHere are the scores:\n")
f = open("scores.dat","rb")
pickleList = pickle.load(f)
print(pickleList)
Any help would be greatly appreciated.