title: Python stats: how do I write it to a (human readable) file
body: <p>I am using Python's hotshot profiler: <a href="http://docs.python.org/2/library/hotshot.html" rel="noreferrer">http://docs.python.org/2/library/hotshot.html</a></p>
  
  <p>It shows how to print the stats:</p>
  
  <pre><code>stats.print_stats(20)
  </code></pre>
  
  <p>But how do I get that into a file? I'm not sure how to get at the information so I can write it to a file using write().</p>
  
  <p>EDIT:</p>
  
  <p>I'd like the same easily readable result as is printed when it's done this way:</p>
  
  <pre><code>stats = hotshot.stats.load("stones.prof")
  stats.strip_dirs()
  stats.sort_stats('time', 'calls')
  stats.print_stats(20) 
  </code></pre>
  
  <p>So it looks like this:</p>
  
  <pre><code>ncalls  tottime  percall  cumtime  percall filename:lineno(function)
       1    3.295    3.295   10.090   10.090 pystone.py:79(Proc0)
  </code></pre>
  
  <p>(So not for it to look like when I open stones.prof)</p>