When you pickle, you pickle one object at a time, so you might have to pickle multiple times.
>>> score = 1
>>> f = open('highscores.p', 'wb')
>>> pickle.dump(score, f)
>>> f.close()
>>> score = 15
>>> f = open('highscores.p', 'wb')
>>> pickle.dump(score, f)
>>> f.close()
>>> f = open('highscores.p', 'rb')
>>> print pickle.load(f)
1
>>> print pickle.load(f)
15
>>> print pickle.load(f)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
EOFError
To fix that, use a while True and a try, except:
>>> highscores = []
>>>
>>> while True:
... try:
... highscores.append(pickle.load(f))
... except EOFError:
... break
...
>>> print highscores
Now all that is left is to get the maximum. You can use the built in max()
function to do this:
>>> print max(highscores)