How to deal with "^ [[A ^ [[B ^ [[C ^ [[D"] when you press the arrow keys when executing python on mac

environment

macOS:Catalina 10.15.7 python:3.8.5 VScode:1.50.1

problem

When I press the arrow keys when executing python on the terminal of VScode, "^ [[A ^ [[B ^ [[C ^ [[D" is entered, and I have to enter the value once in the past again. I had to.

python


^[[A^[[B^[[C^[[D

solution

This time, we will avoid this problem by introducing "rlwrap". We will use "homebrew" for installation, but this time we will omit the installation of "Homebrew". (Because there are already many articles about installing Homebrew.)

procedure

First, search for "Terminal" with "command + space" and start Terminal. Then enter the following.

python


brew install rlwrap

If there is no problem, "rlwrap" should be installed, so check if it was installed normally.

python


$ rlwrap -v
rlwrap 0.43

It's okay if the version is displayed like this.

After that, when running python

python


$ rlwrap python a.py

Just add to the front! (I haven't tried it in languages other than python, so I don't know! sorry! )

bonus

Only for those who use VScode, but I will introduce it because there are convenient settings.

First, install the extension "Code Runner". This extension makes it very easy to execute a supported language by pressing the play button or using a shortcut key. スクリーンショット 2020-10-27 11.26.35.png

Once installed, click on the gear symbol and select "Extention Settings" at the bottom. Next, I think there are "User" and "Workspace", Check "Run in Terminal" in "User". スクリーンショット 2020-10-27 12.52.43.png

Then select "Workspace". Then click "Edit in settings.json" in the "Code-runner: Executor Map" column. スクリーンショット 2020-10-27 11.29.49.png

If you look in the opened settings.json, you will find the following code.

settings.json


"python": "python -u",

Rewrite this as follows and save it.

settings.json


"python": "rlwrap python -u",

By doing this, "rlwrap" will be added automatically when you execute python with "Code Runner", so you do not have to enter it every time.

Recommended Posts

How to deal with "^ [[A ^ [[B ^ [[C ^ [[D"] when you press the arrow keys when executing python on mac
[AtCoder explanation] Control the A, B, (C), D problems of ABC165 with Python!
[AtCoder explanation] Control the A, B, C, D problems of ABC183 with Python!
[AtCoder explanation] Control the A, B, C, D problems of ABC181 with Python!
[Python] How to create a 2D histogram with Matplotlib
How to deal with UnicodeDecodeError when executing google image download
When you want to hit a UNIX command on Python
How to deal with the phenomenon that Python (Jupyter notebook) executed on WSL becomes Aborted
A note on what you did to use Flycheck with Python
[Introduction to Python] How to split a character string with the split function
How to deal with errors when installing Python and pip with choco
How to send a request to the DMM (FANZA) API with python
"Cython" tutorial to make Python explosive: When a function on the C ++ side has an overload.
How to deal with the problem that the current directory moves when Python is executed from Atom
How to deal with the error "Failed to load module" canberra-gtk-module "that appears when you run OpenCV
Things to watch out for when creating a Python environment on a Mac
[AtCoder explanation] Control the A, B, C problems of ABC182 with Python!
What to do if you get a "Wrong Python Platform" warning when using Python with the NetBeans IDE
[Python] How to convert a 2D list to a 1D list
[Python] Explains how to use the range function with a concrete example
How to deal with OAuth2 error when using Google APIs from Python
[AtCoder explanation] Control the A, B, C problems of ABC186 with Python!
How to deal with SSL error when connecting to S3 with boto of Python
How to erase Python 2.x on Mac.
[AtCoder explanation] Control the A, B, C problems of ABC185 with Python!
How to deal with the problem that build fails when CI / CD of Python Function with AWS Amplify
How to draw a vertical line on a heatmap drawn with Python seaborn
[Introduction to Python] How to write a character string with the format function
[AtCoder explanation] Control the A, B, C problems of ABC187 with Python!
[Python] How to deal with module errors
[AtCoder explanation] Control the A, B, C problems of ABC184 with Python!
How to solve the problem that only the process remains when you press cross on the imshow screen of OpenCV
"Cython" tutorial to make Python explosive: Handling when a function on the C ++ side is passed by reference.
How to get started with the 2020 Python project (windows wsl and mac standardization)
How to publish a blog on Amazon S3 with the static Blog engine'Pelican'for Pythonista
How to access the contents of a Linux disk on a Mac (but read-only)
LINUX: How to make arrow keys correspond to 2,4,6,8 on a notebook without a numeric keypad
[Python] How to save images on the Web at once with Beautiful Soup
[AWS] Wordpress How to deal with "The response is not a correct JSON response"
[Python Tips] How to retrieve multiple keys with the maximum value from the dictionary
How to get a list of files in the same directory with python
[Introduction to Python] How to get the index of data with a for statement
How to use the C library in Python
How to read a CSV file with Python 2/3
How to deal with errors when hitting pip ②
Strategy on how to monetize with Python Java
How to deal with SessionNotCreatedException when using Selenium
How to remember when you forget a word
Introduction to Python with Atom (on the way)
Run the output code with tkinter, saying "A, pretending to be B" in python
How to set a shared folder with the host OS in CentOS7 on VirtualBOX
A story that got stuck when trying to upgrade the Python version on GCE
How to build a beautiful Python environment on a new Mac and install Jupter Notebook
How to identify the element with the smallest number of characters in a Python list?
python: 3.8-Handling Exception: you need a C compiler to build uWSGI error with alpine
"Cython" tutorial to make Python explosive: When C ++ code depends on the library. Preparation
A memo on how to overcome the difficult problem of capturing FX with AI
What to do if you can't hit the arrow keys in the Python interactive console
How to convert / restore a string with [] in python
Think about how to program Python on the iPad
[Python] How to draw a line graph with Matplotlib