Guest User

Untitled

a guest
Jun 20th, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.51 KB | None | 0 0
  1. # this try/except block handles accessing a high score
  2. try: # this attempts to open a file
  3. with open('score.dat', 'rb') as file: # opens score.dat to read
  4. highScore = pickle.load(file) # set highScore to the loaded file
  5. except: # if there is no score.dat file, then this creates one. Without this except, the program would crash.
  6. with open('score.dat', 'wb') as file: # opens score.dat to write
  7. pickle.dump(highScore, file) # put the highScore (which is 0 if this runs) in the pickle file
Add Comment
Please, Sign In to add comment