Seeing Escape Characters When Pressing the Arrow Keys in Python Shell

Seeing escape characters when pressing the arrow keys in python shell

Looks like readline is not enabled. Check if PYTHONSTARTUP variable is defined, for me it points to /etc/pythonstart and that file is executed by the python process before going interactive, which setups readline/history handling.

Thanks to @chown here is the docs on this: http://docs.python.org/2/tutorial/interactive.html

How come when I press the Up or Down Arrow keys in the Python interpreter I get ^[[A or ^[[B instead of history?

It looks as if you're using a build from source. It looks like you'll need to rebuild Python after installing the libreadline-dev or equivalent package on your distribution.

Update: There should be no special build steps needed, just running make should do. There are some messages printed at the end about optional modules which couldn't be built because of missing dependencies (in addition to readline, there are also Tcl/Tk, zlib, gdbm and openssl dependencies, for example).

If for some reason just running make doesn't work, try running configure again first (if make doesn't already run it for you).

Python3 shell prints ^H on pressing backspace key on Linux

Try stty erase ^H. If you regret, just use stty erase ^?. If you don't want to do this every time, put stty erase ^H into .bash_profile.



Related Topics



Leave a reply



Submit