title: Open file, read it, process, and write back - shortest method in Python
body: <p>I want to do some basic filtering on a file. Read it, do processing, write it back. </p>
  
  <p>I'm not looking for "golfing", but want the simplest and most elegant method to achieve this. I came up with:</p>
  
  <pre><code>from __future__ import with_statement
  
  filename = "..." # or sys.argv...
  
  with open(filename) as f:
      new_txt = # ...some translation of f.read() 
  
  open(filename, 'w').write(new_txt)
  </code></pre>
  
  <p>The <code>with</code> statement makes things shorter since I don't have to explicitly open and close the file.</p>
  
  <p>Any other ideas ?</p>