title: Python: TemporaryFile returns empty string when read
body: <p>I need to create a file from a string so I can use it as an attachment for an email in Django. After some Googling I found the tempfile module with TemporaryFile but it's not working as I expect.</p>
  
  <p>the following code returns an empty string. </p>
  
  <pre><code>&gt;&gt;&gt; f = tempfile.TemporaryFile()
  &gt;&gt;&gt; f.write('foobar')
  &gt;&gt;&gt; f.read()
  ''
  </code></pre>