title: IPython: redirecting output of a Python script to a file (like bash >)
body: <p>I have a Python script that I want to run in IPython. I want to redirect (write) the output to a file, similar to:</p>
  
  <pre><code>python my_script.py &gt; my_output.txt
  </code></pre>
  
  <p>How do I do this when I run the script in IPython, i.e. like <code>execfile('my_script.py')</code></p>
  
  <p>There is an <a href="http://rcjp.wordpress.com/2009/03/24/redirecting-stdout-within-ipython/" rel="noreferrer">older page</a> describing a function that could be written to do this, but I believe that there is now a built-in way to do this that I just can't find. </p>