I would recommend you to use the pickle library. Further reading: Python serialization - Why pickle (Benefits of pickle). As for your question,
I am struggling because if the file does not
exist, it is trying to read from a non-existant file.
You can use a try...except...
clause to catch FileNotFoundError
import pickle as pkl
# to read the highscore:
try:
with open('saved_scores.pkl', 'rb') as fp:
highscore = pkl.load(fp) # load the pickle file
except (FileNotFoundError, EOFError): # error catch for if the file is not found or empty
highscore = 0
# you can view your highscore
print(highscore, type(highscore)) # thanks to pickle serialization, the type is <int>
# you can modify the highscore
highscore = 10000 # :)
# to save the highscore:
with open('saved_scores.pkl', 'wb') as fp:
pkl.dump(highscore, fp) # write the pickle file