Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Command history in python shell under linux

1,013 views
Skip to first unread message

Stephen Boulet

unread,
May 2, 2002, 12:01:27 AM5/2/02
to
When I hit the up arrow in the python shell, I get:

^[[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

Andrei Kulakov

unread,
May 2, 2002, 7:30:50 AM5/2/02
to
I don't know about RH, but you can compile your python with readline
module. You have to get python source file and edit Modules/Setup file
and uncomment the readlines.c line.

>


--
Cymbaline: intelligent learning mp3 player - python, linux, console.
get it at: cy.silmarill.org

Stephen Boulet

unread,
May 2, 2002, 9:55:59 AM5/2/02
to
Where is readline support enabled?

I tried running './configure --help' in the source directory for python, but
readline wasn't one of the options...

-- Stephen

Joonas Paalasmaa

unread,
May 2, 2002, 10:03:14 AM5/2/02
to
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

Dave Kuhlman

unread,
May 2, 2002, 12:16:05 PM5/2/02
to
Joonas Paalasmaa wrote:

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

Fernando Pérez

unread,
May 2, 2002, 12:58:06 PM5/2/02
to dkuh...@rexx.com

Dave Kuhlman wrote:

>
> 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.

Jochen Küpper

unread,
May 2, 2002, 12:47:47 AM5/2/02
to
On Wed, 01 May 2002 23:01:27 -0500 Stephen Boulet wrote:

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

0 new messages