How to rewrite a text file in Python
<p>So if I have a code like this:</p>

<pre><code>f = open('score.txt','r+')
playersScore = 1
oldscore = (f.read())
oldscore = int(oldscore)
score = oldscore + PlayersScore
f.write(str(score))
f.close()
</code></pre>

<p>The text file has 1 in it. If I try run the code it gives this error:</p>

<blockquote>
  <p>oldscore = int(oldscore)<br>
  ValueError: invalid literal for int() with base 10: ''</p>
</blockquote>

<p>How can I fix this? I'm a python beginner so please keep it simple.</p>