title: [may be duplicate) How to read a number from a file and use it as a variable?
body: <p>I'm new to python so this is most likely basic knowledge, but how do I read a number from a text file and use it as a variable? I'm trying to make a game where it counts your points and saves it to a plain text file, and when you first run the game it checks for that file and reads the points from your last session. I tried this but it didnt work:</p>
  <p>for saving:</p>
  <pre><code>    def save():
          with open('gameSave.txt', 'w') as f:
              for points in points:
                  f.write('%d' % points)
  </code></pre>
  <p>for loading:</p>
  <pre><code>with open(&quot;gameSave.txt&quot;, &quot;r&quot;, encoding=&quot;utf-8&quot;) as g:
     points = g.readlines()
  </code></pre>
  <p>can anyone help? The points just need to be loaded and save as an integer but i can't figure out how.</p>