title: Prepend a line to an existing file in Python
body: <p>I need to add a single line to the first line of a text file and it looks like the only options available to me are more lines of code than I would expect from python. Something like this:</p>
  
  <pre><code>f = open('filename','r')
  temp = f.read()
  f.close()
  
  f = open('filename', 'w')
  f.write("#testfirstline")
  
  f.write(temp)
  f.close()
  </code></pre>
  
  <p>Is there no easier way? Additionally, I see this two-handle example more often than opening a single handle for reading and writing ('r+') - why is that?</p>