I am trying to format my Python code automatically using the format on save feature in vs Code.
I have installed the autopep8 package and added the following configuration to my pyproject.toml file:
[tool.autopep8]
in-place = true
aggressive = 2
when I try like autopep8 test.py it is working. However, when I try to format my code using the format on save feature, I get the following error message:
--in-place cannot be used with standard input
How can I resolve this error and format my code using autopep8 with desired options?
and my vs code settings looks like:
// Python
"[python]": {
"editor.defaultFormatter": "ms-python.autopep8",
},
"python.formatting.provider": "none",
Davood, Go ahead and create a .vscode folder in the root of your project. write a settings.json file in there and add the following configuration:
{
"python.formatting.provider": "autopep8",
"python.formatting.autopep8Args": [
"--max-line-length",
"120"
],
"editor.formatOnSave": true,
"[python]": {
"editor.tabSize": 4,
"editor.insertSpaces": true,
"editor.rulers": [
79,
120
],
"editor.defaultFormatter": "ms-python.autopep8"
}
}
Hope this helps pal, happy coding!!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With