title: Python file is appending output, not overwriting
body: <p>I am trying to read a file and write(overwrite) the file with another value within a loop. </p>
  
  <pre><code>a="1"
  b="2"
  
  for line in list:
      if os.path.exists(str(line.rstrip('\n'))):
          print line
          with open('/ifs/data/Scripts/currentNode.txt','r+') as nodeNumber:
  
              if nodeNumber.readline().rstrip('\n') == a:
                  print "Origin 1"
                  nodeNumber.write("2")
  #                nodeNumber.close()
  
              elif nodeNumber.readline().rstrip('\n') == b:
                  print "Origin 2"
                  nodeNumber.write("1")
  #                nodeNumber.close()
  
          time.sleep(5)
  </code></pre>
  
  <p>The code above only prints "Origin 1". The file currentNode.txt has the number 1 in it. For some reason it does not overwrite the file. If I do a output of the file, I see '1' but I if I open the file I see </p>
  
  <pre><code>1
  2
  </code></pre>
  
  <p>Any ideas why the file isn't being overwritten? I put a sleep of 5 seconds thinking that the code is running to fast.</p>
  
  <p>Thanks.</p>