Code when writing python vscode error alerts, and automatic formatting

python error checking code usually pep8, pylint and flake8, automatic formatting codes usually autopep8, yapf, black. These tools can be installed using pip, described the use of two traditional ways pip.exe mounted and installed in the VScode here.
Reminder: I use pylint]
to be used in order to flake8 flake8 or other tools to work, the prerequisite is to put "python.linting.enabled" value is set to "true" settings.json file, or even installed these tools, but there is no code error reminder.

 

] [Traditional installation
to install an example flake8, remaining similar
method:
1. Open a command line window (press Win + R, input cmd)
2. Input: python -m pip install flake8, the transport operation to wait for the results
[Note] provided that must be added to the python path environment variable.

Method Two:
1. Open a command line window (press Win + R, input cmd)
2. pip.exe dragged into the window cmd
3. Input: pip install flake8, waiting operation result to the transport

Method three:
1. In the directory where pip.exe, press Shift + right mouse button, open a PowerShell window (win10 previous versions can open a command line window directly)
2. Type: cmd, Enter Run
3. Type: pip install flake8 , enter the result can be waiting to run

【在Vscode中安装】
代码错误工具以flake8为例(pylint也是同理的):
1.在VScode配置中打开设置,搜索python.linting.flake8enabled
2.在Settings界面中勾选

Whether to lint Python files using flake8
或者在User Settings.json文件中,
点击左侧默认用户设置"python.linting.flake8Enabled": false的笔形图形,选择“true”;或者直接在右侧栏自定义设置中,添加"python.linting.flake8Enabled": true
3.右下角会弹出配置通知,点Install安装
4.在终端界面会出现下载成功

 

 


格式化代码以yapf为例:
1.在.py文件界面中右键鼠标选择“格式化文件”,或者直接快捷键Shift+Alt+F
2.VScode提供了三种格式化工具

 

或者在Settings.json中点击左侧的笔形图形,修改“python.formatting.provider”的值,若未安装工具,则右下角会弹出配置通知,选择喜欢的工具安装即可。

 

---------------------
参考:https://blog.csdn.net/BNK_along/article/details/84000953

Guess you like

Origin www.cnblogs.com/liuyanhang/p/10984428.html