^[[A
How do I set up things so that I get the previous command? Thanks.
-- Stephen
My versions:
$ rpm -qa | grep python
python-imaging-1.1.2-4mdk
libpython2.2-2.2-9mdk
pythonlib-1.28-1mdk
python-base-2.2-9mdk
python-2.2-9mdk
python-numeric-20.3-2mdk
python-docs-2.2-9mdk
rpm-python-4.0.3-10mdk
libpython2.2-devel-2.2-9mdk
>
--
Cymbaline: intelligent learning mp3 player - python, linux, console.
get it at: cy.silmarill.org
I tried running './configure --help' in the source directory for python, but
readline wasn't one of the options...
-- Stephen
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
dkuh...@rexx.com
http://www.rexx.com/~dkuhlman
>
> 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/
Thanks a lot for the plug ! :) I'm glad to see others are finding it of use.
I'd just like to clarify that while I do think that IPython is far better
than the normal python shell, it still relies on the native python readline
module. So the OP will still have to solve his issue of not having readline
installed, whether for IPython or not. And for that the rest of your tip is
right on. To further help a bit, these days python detects readline's headers
automatically, so if he installs libreadline-devel _first_ and then does a
fully clean build of python, it should automatically pick up readline and he
shouldn't need to do any manual editing of Modules/Setup.
Cheers,
f.
Stephen> When I hit the up arrow in the python shell, I get:
Stephen> ^[[A
Stephen> How do I set up things so that I get the previous command? Thanks.
From my
,----[~/.pythonrc.py]
| # readline
| try:
| import readline
| except ImportError:
| print "Module readline not available."
| else:
| import rlcompleter
| readline.parse_and_bind("tab: complete")
|
| import os
| histfile = os.path.join(os.environ["HOME"], ".python_history")
| try:
| readline.read_history_file(histfile)
| except IOError:
| pass
| import atexit
| atexit.register(readline.write_history_file, histfile)
| del os, histfile
`----
Greetings,
Jochen
--
Einigkeit und Recht und Freiheit http://www.Jochen-Kuepper.de
Liberté, Égalité, Fraternité GnuPG key: 44BCCD8E
Sex, drugs and rock-n-roll