0

Writing things like the bound variables with current values and names, already entered code of defined functions, imports at the beginning, etc., to a .py file? (on win32, just for the lack of built in readline).

EDIT Just the standard installation/package, without things like iPython. :)

I can make python save a history file on clean exits, but I'm interested if there is any way to make the interpreter dump some code it already has. In a human readable format.

It's not a problem at all if it's not exactly the same I entered while the functionality and the visible names are the same.

Reason just curious.


Useless reasons: it would come handy when you hastily help out a friend at an unknown terminal while [s]he's learning the language, just to realize that there is no convenient way to save the work, while putting it into a file and running that arguably would have made things harder to gasp for the comrade. I'm aware there are things like playerpiano, but you see, it's a random terminal where you have no admin rights and there is not internet. :) Happened several times at school, by the way. Please note that the main reason is being curious.

n611x007
  • 8,952
  • 8
  • 59
  • 102
  • 1
    Looks like iPython is what you're looking for :) http://stackoverflow.com/questions/947810/how-to-save-a-python-interactive-session – Zashas Jun 09 '12 at 15:15
  • I love ipython but I'm curious if a more bare solution exists. the other question is superb by the way, if I can install something. – n611x007 Jun 09 '12 at 15:16
  • 1
    If you're trying to come up with your own solution, I would check out the [inspect module](http://docs.python.org/library/inspect.html) – Joel Cornett Jun 09 '12 at 16:07
  • 1
    Also the [dis](http://docs.python.org/library/dis.html) module may help as well. – Joel Cornett Jun 09 '12 at 16:36

1 Answers1

2

Some Python shells give you a chance to save your work. IDLE will let you save the text of the interactive session to a file, for example, so at least you have the text of the things you've created.

IPython offers IPython Notebook, which lets you save interactive sessions.

Ned Batchelder
  • 364,293
  • 75
  • 561
  • 662