title: Bad file descriptor error
body: <p>If I try executing the following code</p>
  
  <pre><code>f = file('test','rb')
  fout = file('test.out','wb')
  
  for i in range(10):
      a = f.read(1)
      fout.write(a)
  
  f.close()
  f = fout
  f.seek(4)
  
  print f.read(4)
  </code></pre>
  
  <p>Where <code>'test'</code> is any arbitrary file, I get:</p>
  
  <pre><code>Traceback (most recent call last):
    File "testbad.py", line 12, in &lt;module&gt;
      print f.read(4)
  IOError: [Errno 9] Bad file descriptor
  </code></pre>
  
  <p>If however, I change just the fout line to use a temporary file:</p>
  
  <pre><code>import tempfile
  
  f = file('test','rb')
  fout = tempfile.NamedTemporaryFile()
  
  for i in range(10):
      a = f.read(1)
      fout.write(a)
  
  f.close()
  f = fout
  f.seek(4)
  
  print f.read(4)
  </code></pre>
  
  <p>There are no errors. Does anyone know why this is? I would have expected the first case to work, but I must be doing something wrong.</p>
  
  <p>Thanks in advance for any help!</p>