title: Export Python interpreter history to a file?
body: <p>Many times I will use the Python interpreter to inspect variables and step through commands before I actually write to a file. However by the end I have around 30 commands in the interpreter, and have to copy/paste them into a file to run. Is there a way I can export/write the Python interpreter history into a file?</p>
  
  <p>For example</p>
  
  <pre><code>&gt;&gt;&gt; a = 5
  &gt;&gt;&gt; b = a + 6
  &gt;&gt;&gt; import sys
  &gt;&gt;&gt; export('history', 'interactions.py') 
  </code></pre>
  
  <p>And then I can open the <code>interactions.py</code> file and read:</p>
  
  <pre><code>a = 5
  b = a + 6
  import sys
  </code></pre>