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:
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
2009-11-18 20:30:06
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
2009-11-18 21:11:46
This is a very cool piece of information.
jathanism
2009-11-19 01:52:36
+6
A:
If you compile python with readline support, the REPL environment should do this for you.
Corey Porter
2009-11-18 20:30:41
+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
2009-11-19 01:10:08