I am trying to create a file that will hold just one number; the highscore to a game I am writing.
I have
f = open('hisc.txt', 'r+')
and
f.write(str(topScore))
What I want to know how to do is to:
- Erase the entire file
- Get the number in the file and make it a variable in the game
- Check if the topScore is higher than the number in the file, and if so, replace it
Putting it all together:
Maybe it's my preference, but I am much more used to the idiom in which on initialization, you do
And then at the end of the game: