I want to format and check Python code to my liking on VS Code

Motivation

With the default pylint, it was inconvenient because the code was not formatted as expected, so I will summarize how to change the detailed settings to your liking.

pip installation

Not required if already installed.

sudo apt install -y python-pip

Install formatter

flake8: Code check (error warning) autopep8: Code formatting

pip install flake8 autopep8

setting of setting.json

Open setting.json from VS Code settings and add a note in{}

{
   "python.linting.pylintEnabled": false,
   "python.linting.flake8Enabled": true,
   "python.formatting.autopep8Args": [
       "--max-line-length", "500",
       "--ignore", "E501",
   ],
   "python.linting.flake8Args": [
       "--ignore=E501,E266,E302",
   ]
}

"python.linting.pylintEnabled": false Disable pylint "python.linting.flake8Enabled": true Enable flake8 "--max-line-length", "500" Changed the character limit of one line of autopep8 to 500 (substantially none) "--ignore", "E501" Remove the character limit for one line of autopep8 I think either one of the above is good, but I'm putting it in for the time being "--ignore=E501,E266,E302" E501: Lifting the character limit on one line of flake8 E266: Removed warning when flake8 has too many #s E302: Removes warning when there are no line breaks between functions or classes

Actually use

You should be able to use it with Ctrl + Shift + ʻI`. If you can't use it, please check if the Python version that introduced flake8 etc. with pip and the Python version of VS Code are the same.

reference

https://qiita.com/psychoroid/items/2c2acc06c900d2c0c8cb https://qiita.com/ciloholic/items/9de9391f8457dc9bc60c

Recommended Posts

I want to format and check Python code to my liking on VS Code
I want to write in Python! (1) Code format check
I want to be able to run Python in VS Code
I want to use VS Code and Spyder without anaconda! !! !!
I want to make C ++ code from Python code!
I want to handle optimization with python and cplex
I want to AWS Lambda with Python on Mac!
I tried input interpolation on UE4 Python VS Code
I made an action to automatically format python code
I want to announce my graduation thesis on IPython Notebook
I want to know the features of Python and pip
I want to map the EDINET code and securities number
Python 3.6 on Windows ... and to Xamarin.
Let's statically check and format the code of E2E automatic test written in Python [VS Code]
I want to absorb the difference between the for statement on the Python + numpy matrix and the Julia for statement
I want to debug with Python
I tried Python! ] Can I post to Kaggle on my iPad Pro?
I want to solve APG4b with Python (only 4.01 and 4.04 in Chapter 4)
I want to know if you install Python on Mac ・ Iroha
I want to use both key and value of Python iterator
I want to check the position of my face with OpenCV!
Code Python to check and graph if it follows Benford's law
I want to hack Robomaster S1 ① Rooting and file configuration check
How to build Python and Jupyter execution environment with VS Code
How to check and change Linux permissions (permissions) (chmod) (I want to be saved from Permiss on denied)
I want to use jar from python
I want to build a Python environment
I want to use Linux on mac
I want to analyze logs with Python
I want to play with aws with python
I want to develop Android apps on Android
I was addicted to creating a Python venv environment with VS Code
Steps to create a Python virtual environment with VS Code on Windows
(Python Selenium) I want to check the settings of the download destination of WebDriver
Try to write python code to generate go code --Try porting JSON-to-Go and so on
I want to make a web application using React and Python flask
I want to pass an argument to a python function and execute it from PHP on a web server
I want to do Dunnett's test in Python
I want to use MATLAB feval with python
I want to use Python in the environment of pyenv + pipenv on Windows 10
I want to memoize including Python keyword arguments
I stumbled on the character code when converting CSV to JSON in Python
I want to create a window in Python
Anyway, I want to check JSON data easily
I want to email from Gmail using Python.
[Python] I want to manage 7DaysToDie from Discord! 1/3
I want to drop a file on tkinter and get its path [Tkinter DnD2]
I want to make a game with Python
I want to write an element to a file with numpy and check it.
I have a private Python package but I want to install pipenv on GitHub Actions and build a Docker Image
I want to merge nested dicts in Python
I want to make fits from my head
I want to use Temporary Directory with Python2
I want to exe and distribute a program that resizes images Python3 + pyinstaller
I want to use ceres solver from python
#Unresolved I want to compile gobject-introspection with Python3
I want to solve APG4b with Python (Chapter 2)
I want to do pyenv + pipenv on Windows
I want to convert horizontal text to vertical text and post it on Twitter etc.
List of Python code to move and remember
[Python] I want to manage 7DaysToDie from Discord! 2/3