python prompt with a bash like interface
I am using the python prompt to practice some regular expressions. I was wondering if there 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/w开发者_开发知识库indows. thanks
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
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
You want ipython.
If you compile python with readline support, the REPL environment should do this for you.
精彩评论