tags:

views:

174

answers:

4
+1  Q: 

Interactive python

Possible Duplicate:
How to save a Python interactive session?

Can i save everything I type into a python session when "brain storming"?

For instance, not just default variables but of course even overriding the shell. I of course mean by invoking the actual python executable.

I seriously hope this is not a stupid question.

I need rep of course too, so this probes me a bit.

+3  A: 

Not sure if you can do this with the Python shell. But it's possible with IPython which gives you a lot more:

ars
+9  A: 

iPython (as suggested in another answer) is indeed a good suggestion, but if you prefer the good old Python interactive interpreter it's not too hard to do it there either. Set your environment variable PYTHONSTARTUP to point to a file that contains, for example:

import atexit
import readline
try:
    readline.read_history_file('.PythonHistory')
except OSError:
    pass
atexit.register(lambda: readline.write_history_file('.PythonHistory'))

this can be tweaked as you wish (e.g. to load and save the same file no matter what directory you're starting from) but I kind of like this simple version as it makes it very easy to have different "sessions" remembered in different working directories.

Alex Martelli
I like this the best. I wanted this type of control and thank you for the imports.
phreaki
+2  A: 

Others (ars, Alex Martelli) have given direct answers to the question. For myself, I've found a more effective strategy is to write all of the commands into a text editors and either execute saved scripts and/or copy-and-paste into python or ipython. I find that I can keep myself more organized that way.

Mr Fooz
A: 

There is as well the Bpython interpreter :

http://www.bpython-interpreter.org/

This is the list of features which include the save code and even send the code to a pastebin service.

  • In-line syntax highlighting.
  • Readline-like autocomplete with suggestions displayed as you type.
  • Expected parameter list for any Python function.
  • "Rewind" function to pop the last line of code from memory and re-evaluate.
  • Send the code you've entered off to a pastebin.
  • Save the code you've entered to a file.
  • Auto-indentation.
Chmouel Boudjnah