title: reading and writing to the same file simultaneously in python
body: <p>Is it possible to read and write simultaneously to the same file? I have this chunk of code:</p>
  
  <pre><code>with open(total_f, 'w') as f:
      s= len(resu)
      #print s
      f.write ("the total number is {}\n".format(s))
      f.write('\n'.join(map(str, resu)))
  
  with open(total_f ,'r') as f:
      content = f.read()
      count = content.count("FFFF")
      print count
  </code></pre>
  
  <p>but I need them to be together, because I want to write the result of <code>count</code> in <code>total_f</code>.</p>
  
  <p>I tried to put in the read/write together like this: </p>
  
  <pre><code>with open(total_f, 'rw') as f:# i want to read and write at the same time
      s= len(resu)
      content = f.read()
      count = content.count("FFFF")  
      #print s
      f.write ("the total number is {}\n".format(s))
      f.write ("the total number is {}\n".format(count))
      f.write('\n'.join(map(str, resu)))
  </code></pre>
  
  <p>But it's still not working, and so I'm not sure if that's correct.</p>