title: Error when attempting to write cProfile information to file
body: <p>I am attempting to load a cProfile profile, do some sorting and finessing, then output the results to a file.  Based on the <a href="https://docs.python.org/2/library/profile.html#the-stats-class" rel="noreferrer">documentation</a>, I thought I could simply pass a file object and the <code>print_stats</code> function would redirect to that stream.</p>
  
  <p>Here is the code I am attempting to use:</p>
  
  <pre><code>import sys,pstats
  s = open('output.txt', 'w')
  p = pstats.Stats('profile.dat', s)
  </code></pre>
  
  <p>and here is the resulting error:</p>
  
  <pre><code>TypeError: Cannot create or construct a &lt;class pstats.Stats at 0xbaa870&gt; object from '&lt;open file 'output.txt', mode 'w' at 0xb2ef60&gt;''
  </code></pre>
  
  <p>I should also add that when I do not pass an object to the stream parameter, the output appears as normal in the terminal.</p>