Preferences->Settings, find the two settings for the static code prompt in settings.json, and modify them As follows: "python.linting.pylintEnabled":fal"/> Preferences->Settings, find the two settings for the static code prompt in settings.json, and modify them As follows: "python.linting.pylintEnabled":fal">

Home  >  Article  >  System Tutorial  >  A guide to writing Python correctly using VSCode

A guide to writing Python correctly using VSCode

WBOY
WBOYforward
2023-12-30 20:05:33751browse

We will find that there will be many warnings about formatting issues in the code when writing. So how do you automatically format your code? This is what will be introduced in this issue.

1. Configure flake8

When you write code after installing flake8, the editor will prompt you where there are errors, and it will also prompt if the code format is not standardized. Open the command line. VSCode can run the terminal directly. Press the shortcut key Ctrl ` and enter "pipinstallflake8". After successfully installing flake8, open File->Preferences->Settings and find the two settings for static code prompts in settings.json. And modify it as follows:

"python.linting.pylintEnabled": false
"python.linting.flake8Enabled": true

A guide to writing Python correctly using VSCode

2. Configure yapf

After installing yapf, press Alt Shift F in VScode to automatically format the code. Open the command line as above. After successfully installing yapf, enter "pip install yapf", open File-> Preferences-> Settings, find this setting in settings.json, and modify it as follows: "python.formatting.provider": "yapf",
A guide to writing Python correctly using VSCode

3. Several simple configurations

Automatically insert a new line at the end when saving the file, because Python's format has a new line at the end of the program.

"files.insertFinalNewline": true

The file is automatically saved and the delay time can be set.

"files.autoSave": "afterDelay"
"files.autoSaveDelay": 1000

The latter one is to set the delay time, here it is set to 1000ms.

The above is the detailed content of A guide to writing Python correctly using VSCode. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:linuxprobe.com. If there is any infringement, please contact admin@php.cn delete