Visual Studio Code 和 Autopep8 格式化程序

Daw*_*fer 9 python autopep8 visual-studio-code

我正在尝试将 python 格式化程序设置为 autopep8。它已正确安装,但它从未作为 VSCode 中的格式化选项。

"python.formatting.autopep8Path": "C:\\Users\\DawsonSchaffer\\AppData\\Roaming\\Python\\Python39\\Scripts\\autopep8.exe",
    "python.formatting.autopep8Args": [
        "--max-line-length",
        "160",
        "--aggressive",
        "--aggressive",
        "--in-place"
    ],
    "[python]": {
        "editor.defaultFormatter": "autopep8",
    },
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

我已经更改了所有设置。但是我不确定要为 autopep8 添加什么。

"[python]": {
    "editor.defaultFormatter": "ms-python.python",
},

or

"[python]": {
    "editor.defaultFormatter": "autopep8",
},
Run Code Online (Sandbox Code Playgroud)

此外,autopep8 在控制托盘中不可用。

在此输入图像描述

谢谢道森

Ste*_*SFT 8

这是要配置的

  "[python]": {
    "editor.defaultFormatter": "ms-python.python"
  },
Run Code Online (Sandbox Code Playgroud)

在settings.json中。

您可以这样设置以应用 autopep8 格式:

"python.formatting.provider": "autopep8",
"editor.formatOnSave": true,
"files.autoSave": "afterDelay",
Run Code Online (Sandbox Code Playgroud)

相关官方文档。