Command history in python shell under linux
Dave Kuhlman
dkuhlman at rexx.com
Thu May 2 12:16:05 EDT 2002
Joonas Paalasmaa wrote:
> Stephen Boulet wrote:
>> Where is readline support enabled?
>>
>> I tried running './configure --help' in the source directory for
>> python, but readline wasn't one of the options...
>
> Uncomment and modify some readline-related lines in Modules/Setup
> after running ./configure
Trying to save you a bit of frustration in advance ... When I
recompiled the source after uncommenting the readline line in
Modules/Setup, I believe I had to install the package
libreadline-dev in order to get a header file needed by readline.
A couple of additional suggestions:
1. For a fancier Python shell, take a look at IPython:
http://www-hep.colorado.edu/~fperez/ipython/
2. The following in the Python standard distribution shows (a) how
to set up history that lasts across invocations of the Python
interpreter and (b) how to install completion of Python identifiers.
http://www.python.org/doc/current/lib/readline-example.html
http://www.python.org/doc/current/lib/module-rlcompleter.html
3. My Python initialization file is below. Set the PYTHONSTARTUP
environment variable so that it will be executed. The following in
my .bashrc-private file works for me:
export PYTHONSTARTUP=$HOME/initialize.py
#========================================================
# initialize.py
# Dave's initialization file for Python interactive sessions.
import sys, os, readline
histfile = os.path.join(os.environ["HOME"], ".pyhist")
try:
readline.read_history_file(histfile)
except IOError:
pass
import atexit
atexit.register(readline.write_history_file, histfile)
del os, histfile
try:
import readline
except ImportError:
print "Module readline not available."
else:
import rlcompleter
readline.parse_and_bind("tab: complete")
#========================================================
- Dave
--
Dave Kuhlman
dkuhlman at rexx.com
http://www.rexx.com/~dkuhlman
More information about the Python-list
mailing list