tags:

views:

134

answers:

4

I am using the python prompt to practice some refular expressions. I was wondering if theere was a way to use the up/down arrows (like bash) to cycle through the old commands typed. I know its possible since it works on python on cygwin/windows. thanks

+4  A: 

You want ipython.

Jonathan Feinberg
+4  A: 

Use the rlcompleter module to get both readline and completion.

Sample PYTHONSTARTUP code:

try:
  import readline
except ImportError:
  print "Module readline unavailable."
else:
  import rlcompleter
  readline.parse_and_bind("tab: complete")

Sample .bashrc code to set your python startup file:

if [ -f ~/.pythonstartup.py ]
then
  export PYTHONSTARTUP=~/.pythonstartup.py
fi
Roger Pate
Thank you! This works in my existing python installation without having to install ipython or compiling python with readline support as mentioned in the other answers.
jinxed_coder
This is a very cool piece of information.
jathanism
+6  A: 

If you compile python with readline support, the REPL environment should do this for you.

Corey Porter
+3  A: 

As well as compiling with readline enabled as suggested in another answer, you can also use rlrwrap to add readline at run time, even if it wasn't complied in; like so:

rlwrap python
Benji York
Nice! This is useful enough that I'd upvote you twice if I could :).
quark
I did it for you :) marked this awnser up again.
Pradyot