开发者

python prompt with a bash like interface

开发者 https://www.devze.com 2022-12-11 16:20 出处:网络
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

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消