1

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.

2
  • Exact duplicate, I believe: stackoverflow.com/questions/947810/… Commented Jul 25, 2009 at 0:56
  • Indeed, had my search been just a little different. Commented Jul 28, 2009 at 22:34

4 Answers 4

9

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.

Sign up to request clarification or add additional context in comments.

1 Comment

I like this the best. I wanted this type of control and thank you for the imports.
3

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

Comments

2

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.

Comments

0

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.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.