Python AutoPep8 格式不适用于最大行长度参数

新手上路,请多包涵

我注意到一件奇怪的事情,当我们设置时,VSCode 中的 autopep8 自动格式化不起作用

    "python.formatting.autopep8Args": [
        "--line-length 119"
    ],

但是,如果此设置处于行长 79 的默认模式下,则效果很好。 autopep8 是否仅适用于不超过 79 的行长度,或者我在 VSCode 中犯了任何错误。我需要的主要功能是当我的 python 程序行太长时,它应该能够将它分成多行。我不想继续使用 79 个字符的方法。我的首选方法是 119 个字符。目前,我必须手动缩进大行。除了支持 119 个字符和超过 119 个字符的自动缩进行的 pep8 之外,还有其他格式吗?

我附上我的 settings.json 文件数据

{
    "window.zoomLevel": 1,
    "python.dataScience.sendSelectionToInteractiveWindow": true,
    "diffEditor.ignoreTrimWhitespace": false,
    "editor.fontSize": 16,
    "python.formatting.provider": "autopep8",
    "editor.formatOnPaste": true,
    "editor.formatOnSave": true,
    "editor.formatOnType": true,
    "python.autoComplete.addBrackets": true,
    "python.formatting.autopep8Args": [
        "--line-length 119"
    ],
    // "python.linting.flake8Args": [
    //     "--max-line-length=120"
    // ],
    "files.autoSaveDelay": 10000,
    "editor.defaultFormatter": "ms-python.python",
    "files.autoSave": "afterDelay",
    "files.trimTrailingWhitespace": true,
    "files.trimFinalNewlines": true,
    "editor.quickSuggestions": true,
    "editor.codeActionsOnSave": null,
}

原文由 Mohit Kumar 发布,翻译遵循 CC BY-SA 4.0 许可协议

阅读 1.9k
2 个回答

这应该工作 -

 "python.formatting.provider": "autopep8",
"python.formatting.autopep8Args": [
    "--max-line-length",
    "120",
    "--experimental"
]

原文由 PD Wanjari 发布,翻译遵循 CC BY-SA 4.0 许可协议

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题