Why can't I write to a file that I open in python?
<p>I opened the python interpreter and tried to write to a file I was reading at the same time:</p>

<pre><code>file = open("foo.txt")
lines = file.readlines()
for i in range(0, 3):
    file.write(lines[0])
</code></pre>

<p>However, python issued an error that noted I had a bad file handler when I tried to execute <code>file.write(lines[0])</code>. Why can't I write the first line of a file to the file itself?</p>
