Python编码风格指导(PEP8)要求每行代码不得超过80个字符。在VSCode中Pyhon常用代码检查工具是pylint和flake8,常用代码格式化工具是yapf、autopep8和black。
针对代码过长导致格式化时自动换行,在vsc的setting.json中修改格式化工具的每行最大字符个数,下面是常用的配置参数。
```bash
"editor.formatOnSave": true,
"editor.formatOnPaste": true,
"editor.formatOnType": true,
"terminal.integrated.cursorBlinking": true,
// yapf
"python.formatting.provider": "yapf",
"python.formatting.yapfArgs": [
"--style",
"{column_limit: 200}"
],
// autopep8
"python.formatting.provider": "autopep8",
"python.formatting.autopep8Args": [
"--max-line-length=200"
],
// black
"python.formatting.provider": "black",
"python.formatting.blackArgs": [
"--line-length",
"200"
],
// pylint
"python.linting.pylintEnabled": true,
// flake8
"python.linting.flake8Enabled": true,
"python.linting.flake8Args": [
"--max-line-length=200"
],
```