python shell that saves history of typed in commands that will persist between reboots
Ben Finney
ben+python at benfinney.id.au
Wed Nov 16 16:09:18 EST 2011
goldtech <goldtech at worldpost.com> writes:
> Using Windows. Is there a python shell that has a history of typed in
> commands?
I don't know about MS Windows, but the Python interactive shell can be
linked with the GNU Readline library for managing its command line
<URL:http://docs.python.org/library/readline.html> including editing
features, tab completion, history management, and a persistent history
file.
You can then use that functionality in your Python interactive startup
file. Here's mine:
=====
# $HOME/.pythonrc
# User configuration for interactive Python shell.
import sys
import os
import os.path
import atexit
# Tab completion with readline.
# Cribbed from <URL:http://docs.python.org/lib/module-rlcompleter.html>.
try:
import readline
except ImportError:
sys.stderr.write("Module readline not available.\n")
else:
import rlcompleter
# Enable tab completion.
readline.parse_and_bind("tab: complete")
# Persistent command history.
histfile = os.path.join(os.environ["HOME"], ".python_history")
try:
readline.read_history_file(histfile)
except IOError:
# Existing history file can't be read.
pass
atexit.register(readline.write_history_file, histfile)
del histfile
del sys, os, atexit
=====
Reading the documentation, I see that the ‘readline’ library is only
linked with Python on Unix-alike operating systems. Yet another reason
why MS Windows is not a good choice for developing software I guess.
--
\ “The difference between religions and cults is determined by |
`\ how much real estate is owned.” —Frank Zappa |
_o__) |
Ben Finney
More information about the Python-list
mailing list