How can I save / copy classes & functions I've written in the python interpreter?
<p>How can you save functions/ classes you've writing in a python interactive session to a file?  Specifically, is there a way in pydev / eclipse's interactive session (on a mac) to do this?</p>

<p>I just started learning python - and am enjoying using the interpreter's interactive session for testing and playing with modules I've written.  However, I find myself writing functions in the interpreter, which I think, oh it would be cool to save that to my script files.  How do I do this?</p>

<p>I tried:</p>

<pre><code>import pickle
pickle.dump(my_function, open("output.p", "w"))
</code></pre>

<p>But it seems to be more of a binary serialization, or at least nothing that I could copy and paste into my code...</p>

<p>Are there ways to see the code behind classes &amp; functions I've defined in the interpreter?  And then copy them out of the interpreter?</p>

<p><strong>Update:</strong></p>

<p>Ok, here's what I've learned so far:</p>

<ul>
<li>I missed the easiest of all - PyDev's interactive session in eclipse allows you to right click and save your session.  Still have to remove >>>'s, but gets the job done.</li>
<li><a href="http://ipython.scipy.org/moin" rel="nofollow">IPython</a> is apparently the way to go to do this.</li>
<li><a href="http://stackoverflow.com/questions/947810/how-to-save-a-python-interactive-session">http://stackoverflow.com/questions/947810/how-to-save-a-python-interactive-session</a> has more details.</li>
</ul>
