Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I set max line length in vscode for python?

For JavaScript formatter works fine but not for Python. I have installed autopep8 but it seems that I can't set max line length. I tried this:

"python.formatting.autopep8Args": [
    "--max-line-length",
    "79",
    "--experimental"
  ]

and my settings.json looks like this:

{
  "workbench.colorTheme": "One Dark Pro",
  "git.autofetch": true,
  "workbench.iconTheme": "material-icon-theme",
  "git.enableSmartCommit": true,
  "terminal.integrated.shell.windows": "C:\\WINDOWS\\System32\\cmd.exe",
  "[javascript]": {
    "editor.defaultFormatter": "esbenp.prettier-vscode"
  },
  "[html]": {
    "editor.defaultFormatter": "vscode.html-language-features"
  },
  "javascript.updateImportsOnFileMove.enabled": "always",
  "[javascriptreact]": {
    "editor.defaultFormatter": "esbenp.prettier-vscode"
  },
  "liveServer.settings.donotShowInfoMsg": true,
  "editor.formatOnSave": true,
  "window.zoomLevel": 1,
  "vscode-w3cvalidation.validator-token": "Fri, 07 Aug 2020 07:35:05 GMT",
  "python.formatting.provider": "autopep8",
  "python.formatting.autopep8Args": [
    "--max-line-length",
    "79",
    "--experimental"
  ],
  "python.autoComplete.addBrackets": true,
  "python.autoComplete.extraPaths": []
}

Any ideas how to fix that?

like image 829
Jan Ponichter Avatar asked Dec 08 '25 08:12

Jan Ponichter


2 Answers

Specifically for autopep8:

    "autopep8.args": [
        "--max-line-length", "119"
    ],

This is according to https://github.com/microsoft/vscode-autopep8

like image 161
kolis Avatar answered Dec 09 '25 22:12

kolis


From autopep8-usage, the default value of max-line-length is 79, so you can change to other value and have a try.

About the effect of autopep8 in vscode, I made a test with the same settings as yours, like the following screenshot shows:

enter image description here

every print sentence line-length is over 79, the first and the second print() parameters are expressions, and the setting works for the first one, not for the second. This is because setting applicable rules are provided by python extension and it has own caculation mechanism.

When it comes to print strings, the setting doesn't work, so if you mean this in your question, you can add the following code in user settings.json.

"editor.wordWrap": "wordWrapColumn",
"editor.wordWrapColumn": 79
like image 45
Molly Wang-MSFT Avatar answered Dec 09 '25 20:12

Molly Wang-MSFT



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!