title: Python - tempfile.TemporaryFile cannot be read; why?
body: <p>The <a href="http://docs.python.org/library/tempfile.html#tempfile.TemporaryFile" rel="noreferrer">official documentation for TemporaryFile</a> reads:</p>
  
  <blockquote>
    <p>The mode parameter defaults to 'w+b'
    so that the file created <strong>can be read
    and written without being closed</strong>.</p>
  </blockquote>
  
  <p>Yet, the below code does not work as expected:</p>
  
  <pre><code>import tempfile
  
  def play_with_fd():
      with tempfile.TemporaryFile() as f:
          f.write('test data\n')
          f.write('most test data\n')
  
          print 'READ:', f.read()
  
          f.write('further data')
  
          print 'READ:', f.read()
  
          f.write('even more')
          print 'READ:', f.read()
  
          print 'READ:', f.read()
          print 'READ:', f.read()
  
  if __name__ == '__main__':
      play_with_fd()
  </code></pre>
  
  <p>The output I get is:</p>
  
  <pre><code>&gt; python play.py 
  READ: 
  READ: 
  READ: 
  READ: 
  READ: 
  </code></pre>
  
  <p>Can anyone explain this behavior? Is there a way to read from temporary files at all? (without having to use the low-level mkstemp that wouldn't automatically delete the files; and I don't care about named files)</p>