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
Numpy Sum Elements in Array Based on Its Value
Change User-Agent for Selenium Web-Driver
What Is the Point of Indexing in Pandas
How to Find Char in String and Get All the Indexes
Python: How to Make the Ansi Escape Codes to Work Also in Windows
How to Convert a Time.Struct_Time Object into a Datetime Object
Split Text Lines in Scanned Document
Pandas Make New Column from String Slice of Another Column
How to Escape Strings for SQLite Table/Column Names in Python
Timeout for Python Requests.Get Entire Response
Let JSON Object Accept Bytes or Let Urlopen Output Strings
Python: Simple List Merging Based on Intersections
Adding a Background Image to a Plot
How to Set Up a Virtual Environment for Python in Visual Studio Code
How to Clone a Django Model Instance Object and Save It to the Database