Read in file - change contents - write out to same file
<p>I have to read in a file, change a sections of the text here and there, and then write out to the same file.</p>

<p>Currently I do:</p>

<pre><code>f = open(file)
file_str = f.read() # read it in as a string, Not line by line
f.close()
#
# do_actions_on_file_str
#
f = open(file, 'w') # to clear the file
f.write(file_str)
f.close()
</code></pre>

<p>But I would imagine that there is a more pythonic approach that yields the same result.</p>

<p>Suggestions?</p>
