【发布时间】:2019-09-10 12:29:20
【问题描述】:
我遇到的问题与我的 Python 文件在 Visual Studio Code 中的自动格式化有关。
我喜欢在 Python 中使用制表符,因为它更容易保持一致并更快地键入代码;但是,当我在 Visual Studio Code 上保存时,保存时的自动格式会为每一行添加一个额外的空间。这意味着 python 脚本可以工作,但结构看起来不正常。
我已尝试禁用美化,但它仍然会发生。我不认为更漂亮的自动格式格式化 python 反正。我尝试检查设置 JSON 文件,但我认为那里也没有任何内容。
Settings.json:
{
"color-highlight.markerType": "dot-before",
"editor.detectIndentation": false,
"editor.formatOnSave": true,
"editor.tabSize": 3,
"liveServer.settings.donotShowInfoMsg": true,
"prettier.tabWidth": 3,
"python.pythonPath": "C:\\Users\\mtapi\\Anaconda3\\python.exe",
"window.zoomLevel": 1,
"python.condaPath": "C:\\Users\\mtapi\\Anaconda3\\Scripts\\conda.exe",
"terminal.integrated.shell.windows": "C:\\WINDOWS\\System32\\cmd.exe",
"editor.insertSpaces": false,
"prettier.useTabs": true,
"python.linting.pylintEnabled": true,
"python.linting.enabled": true,
"python.linting.pep8Enabled": true,
"editor.mouseWheelZoom": true,
"editor.fontSize": 15,
"workbench.iconTheme": "vscode-icons",
"workbench.colorTheme": "Default High Contrast"
}
这是一个示例脚本保存格式之前:
保存后会发生以下情况:
这在以前没有发生过。让我知道是否有任何令人困惑或需要更多信息
【问题讨论】:
-
之前没有发生什么?
-
这两个设置看起来很可疑:
"editor.tabSize"&"prettier.tabWidth"。尝试将其中一个或两个都设置为 4。根据 PEP8,缩进应该是 4 个空格。所以,1 tab=4spaces 是正确的配置。 -
太棒了!已解决!
-
@Miguel,您能否确认必须更改这些设置中的哪一个或两个?
-
我将 editor.tabSize 和 prettier.tabWidth 设置为 4 个空格。
标签: python visual-studio-code pep8 autopep8