title: Python: Revert sys.stdout to default
body: <p>I wanted to write output to file and hence I did </p>
  
  <pre><code>sys.stdout = open(outfile, 'w+')
  </code></pre>
  
  <p>But then I wanted to print back to console after writing to file</p>
  
  <pre><code>sys.stdout.close()
  sys.stdout = None
  </code></pre>
  
  <p>And I got</p>
  
  <pre><code>AttributeError: 'NoneType' object has no attribute 'write'
  </code></pre>
  
  <p>Obviously the default output stream can't be <code>None</code>, <strong>so how do I say to Python</strong>:</p>
  
  <pre><code>sys.stdout = use_the_default_one()
  </code></pre>