由于某些原因,Visual Studio代码看起来像是将我的代码修改为使用两个选项卡。我已经将我的settings.json更改为使用2个空格来表示制表符,我已经通过按tab按钮进行了验证,正如预期的那样,它使用了2个空格。但是,4个空格(或2个制表符)仍用于Python缩进,如下图所示:

你可以看到它使用了两个(2个间距)的标签。我看了我能找到的每一篇关于配置VS Code Python格式的Stack Overflow帖子,但我所做的都不起作用。它仍然是这样的自动套用格式。这是我的settings.json
{
"python.pythonPath": "venv/bin/python3",
"python.linting.enabled": true,
"editor.tabSize": 2,
"editor.formatOnSave": true,
"editor.detectIndentation": false
}有人知道这是怎么回事吗?对于非Python文件,它工作得很好,所以我不知道这是不是pylint的问题。我都快疯了。
发布于 2019-09-02 11:42:27
我想通了--我把我的格式化程序改成了autopep8,并告诉它使用2个空格。这是我更新的settings.json文件:
{
"python.pythonPath": "venv/bin/python3",
"editor.tabSize": 2,
"editor.formatOnSave": true,
"python.linting.pylintArgs": [
"--indent-string=' '"
],
"python.formatting.autopep8Args": [
"--indent-size=2"
],
"python.linting.pylintEnabled": true,
"python.formatting.provider": "autopep8"
}我对这里正在进行的linting / formatting有一点陌生,但我了解到linting和formatting是不同的:https://code.visualstudio.com/docs/python/editing#_formatting。我的linter可能告诉我我需要两个空格,但我需要在保存文件时将格式化程序配置为使用两个空格进行格式化。
https://stackoverflow.com/questions/57750880
复制相似问题