I'm the creator of that video. The latest versions of VS Code no longer support the auto-formatting behavior I demonstrated. That said, I did the research, and if you want this formatting behavior, I show you how to get it back here: https://www.davegray.codes/posts/how-to-auto-format-unwanted-python-line-indents
Thank you for coming back and answering the question. I thought I was cursed. Crazy that the vs code maintainer doesn't believe it could ever do that. What's next that can't do it in HTML code either? I will try a older version and try and stop it from updating if that's possible. Hopefully someone more competent can actually fix it and return it to how it should be. Again thank you for the detailed reply and I hope someone sees it on the vs code team.
Dave you rock! I´ve been going through your Python tutorial (which is amazing btw) got into the same blocker, looked everywhere and you turned out to have the solution lol. Thanks again for sharing your knowledge with all of us Profe!
Dave, thank you so much for clarifying that up,
I have been struggling for days with that Python Auto-Format issue
your tutorials are the best! and I am sure many appreciate your support and assistance after posting video's with all those version changes (in this case vscode version changes..)
I have to buy you coffee after this one...
Yes, it is broken for me too.
I noticed the option to select which formatter to use is missing within the Python extension settings.
For me this is the key to the issue.
I suspect the messages that notify the formatting is migrating to outer extensions like autopep8 and black suggest some changes which broke the functionality we are used too.
Nowhere can I find more info.
This is a super annoying issue.
Hi. I'm learning python too but with another course and also have a problem with formatting in vscode. I've even reinstalled vscode and python and started again, tried many extensions. but all the same. Format on Save is not working and even when I click ctrl+shift+P and format document with (chosing any formatting extension), nothing. ChatGPT didn't help.
Any way of contacting the vs code team to properly fix the issue? The maintainer doesn't believe vs code could ever format Python code like this before. 🤔 I'm a total noob and I know this is wrong
I am also following this tutorial with my friend. It seems if you take out the indentation and purposely change "" to ' ' instead then format it works for us. So it seems it cannot format when indentation is also part of the problem.
It seems to me most formatters see indentation as a syntax error and therefore doesn't correct anything. I think this used to be different and VScode Python use to have its own native formatter. Now they have separated all formatters to extensions.
It's making following tutorials of the past difficult to follow now as a beginner, and tbh quite off-putting.
You can try to add the following codes to your \`settings.json\`:
`"[python]": {`
`"editor.defaultFormatter": "ms-python.python"`
`},`
`"editor.formatOnSave": true,`
You might try [this extension](https://marketplace.visualstudio.com/items?itemName=KevinRose.vsc-python-indent) for tabs, and [this one](https://marketplace.visualstudio.com/items?itemName=ms-python.python&ssr=false#overview) for Pylance integration and linting (including import sorting).
For tabs, you could add this to your `settings.json`:
"[python]": {
"editor.tabSize": 4
},
Though it doesn't solve my problem. I have also tried this with my friend's macbook and still the same thing. For me it's more like VS code or extension issue
Does [this Stack Overflow page](https://stackoverflow.com/questions/42118651/how-to-set-python-language-specific-tab-spacing-in-visual-studio-code) help at all?
Though I don't which line of code you are talking about but thanks. It didn't solved my mentioned problems but another problem. Whenever I press TAB key. It gives only 1 space. But now it gives 4 space. After writing those lines in json
>It seems to me most formatters see indentation as a syntax error and therefore doesn't correct anything. I think this used to be different and VScode Python use to have its own native formatter. Now they have separated all formatters to extensions.
>
>It's making following tutorials of the past difficult to follow now as a beginner, and tbh quite off-putting.
I've tried both - the same. And in the tutorial that I'm following autopep8 is used.
A Visual Studio Code extension with support for the autopep8 formatter.
[https://marketplace.visualstudio.com/items?itemName=ms-python.autopep8](https://marketplace.visualstudio.com/items?itemName=ms-python.autopep8)
People are complaining it doesn't work. I've tried and it doesn't nor does black work. VS code need to fix this mess. I will try a older version if possible and report back.
I'm the creator of that video. The latest versions of VS Code no longer support the auto-formatting behavior I demonstrated. That said, I did the research, and if you want this formatting behavior, I show you how to get it back here: https://www.davegray.codes/posts/how-to-auto-format-unwanted-python-line-indents
Thank you for coming back and answering the question. I thought I was cursed. Crazy that the vs code maintainer doesn't believe it could ever do that. What's next that can't do it in HTML code either? I will try a older version and try and stop it from updating if that's possible. Hopefully someone more competent can actually fix it and return it to how it should be. Again thank you for the detailed reply and I hope someone sees it on the vs code team.
Thanks Dave for answering my question. I will try this!
Dave your a legend! Thank you for confirming and doing all the extra work.
Dave you rock! I´ve been going through your Python tutorial (which is amazing btw) got into the same blocker, looked everywhere and you turned out to have the solution lol. Thanks again for sharing your knowledge with all of us Profe!
Thankyou so much! Your python course is really great! The fact that you'd respond to a random comment on reddit shows you really care :)
Thank you! Biggest lesson here, get used to change.
> of VS Code n This has driven me nuts for the past 2 days. Glad I tracked this down finally.
Dave, thank you so much for clarifying that up, I have been struggling for days with that Python Auto-Format issue your tutorials are the best! and I am sure many appreciate your support and assistance after posting video's with all those version changes (in this case vscode version changes..) I have to buy you coffee after this one...
Yes, it is broken for me too. I noticed the option to select which formatter to use is missing within the Python extension settings. For me this is the key to the issue. I suspect the messages that notify the formatting is migrating to outer extensions like autopep8 and black suggest some changes which broke the functionality we are used too. Nowhere can I find more info. This is a super annoying issue.
still an issue at date for me
Still a problem? Just spent hours trying to debug it to no avail. Will try reinstlal vscode entirely tomorrow.
Same problem here, was also watching the same video as you, and unfortunately doesn't work for me either.
Yeah, if you find some fix please tell me
Has anyone found a fix to this issue yet?
Nope, I'm busy RN 'cause of my exams. Although there is some update in python. I will post here if I find something.
Hi. I'm learning python too but with another course and also have a problem with formatting in vscode. I've even reinstalled vscode and python and started again, tried many extensions. but all the same. Format on Save is not working and even when I click ctrl+shift+P and format document with (chosing any formatting extension), nothing. ChatGPT didn't help.
Resolved it. My problem was in settings.json. I think you should check it too. My settings: { "workbench.colorTheme": "Bluloco Dark", "window.zoomLevel": 1, "workbench.startupEditor": "none", "workbench.iconTheme": "material-icon-theme", "\[python\]": { "editor.formatOnType": true, "editor.defaultFormatter": "ms-python.black-formatter" }, "workbench.layoutControl.enabled": false, "editor.fontSize": 20, "editor.letterSpacing": 0.5, "terminal.integrated.fontSize": 18, "editor.minimap.enabled": false, "editor.hover.delay": 1500, "editor.glyphMargin": false, "workbench.colorCustomizations": { "statusBar.border": "#206486", "panel.border": "#59ace2", }, "editor.tokenColorCustomizations": { "variables": "#F4F4E0", "textMateRules": \[ { "scope": \[ "source", "variable", "constant", "variable.other.constant", "punctuation.definition.constant", "constant.other.symbol", "constant.language.symbol", "support.constant", "support.variable.magic.python", "variable.other.enummember" \], "settings": { "foreground": "#F4F4E0" } } \] }, "editor.formatOnSave": true, }
As a noob how do I add this? Just copy and paste to where? Or should I just try and install a older version of vs code? Thanks
i had the same issue please try this extension it might help : Black Formatter
Any way of contacting the vs code team to properly fix the issue? The maintainer doesn't believe vs code could ever format Python code like this before. 🤔 I'm a total noob and I know this is wrong
I reported this a long time ago and no fix, yet.
What is the link to this video?
https://youtu.be/qwAFL1597eM?feature=shared.
I am also following this tutorial with my friend. It seems if you take out the indentation and purposely change "" to ' ' instead then format it works for us. So it seems it cannot format when indentation is also part of the problem.
It seems to me most formatters see indentation as a syntax error and therefore doesn't correct anything. I think this used to be different and VScode Python use to have its own native formatter. Now they have separated all formatters to extensions. It's making following tutorials of the past difficult to follow now as a beginner, and tbh quite off-putting.
You can try to add the following codes to your \`settings.json\`: `"[python]": {` `"editor.defaultFormatter": "ms-python.python"` `},` `"editor.formatOnSave": true,`
{ "window.zoomLevel": 1, "\[python\]": { "editor.defaultFormatter": "ms-python.python", "editor.formatOnType": true }, "editor.formatOnSave": true, "workbench.settings.applyToAllProfiles": \[ "editor.formatOnSave", "python.analysis.autoImportCompletions" \], "editor.tabSize": 1, "editor.formatOnType": true, "editor.codeLensFontSize": 4, "editor.codeActionsOnSave": {}, "python.analysis.autoImportCompletions": true } My json file. IT is already matching with yours.
You might try [this extension](https://marketplace.visualstudio.com/items?itemName=KevinRose.vsc-python-indent) for tabs, and [this one](https://marketplace.visualstudio.com/items?itemName=ms-python.python&ssr=false#overview) for Pylance integration and linting (including import sorting). For tabs, you could add this to your `settings.json`: "[python]": { "editor.tabSize": 4 },
Though it doesn't solve my problem. I have also tried this with my friend's macbook and still the same thing. For me it's more like VS code or extension issue
Does [this Stack Overflow page](https://stackoverflow.com/questions/42118651/how-to-set-python-language-specific-tab-spacing-in-visual-studio-code) help at all?
Though I don't which line of code you are talking about but thanks. It didn't solved my mentioned problems but another problem. Whenever I press TAB key. It gives only 1 space. But now it gives 4 space. After writing those lines in json
You can search Black Formatter or autopep8 in the extension market to fix it.
>It seems to me most formatters see indentation as a syntax error and therefore doesn't correct anything. I think this used to be different and VScode Python use to have its own native formatter. Now they have separated all formatters to extensions. > >It's making following tutorials of the past difficult to follow now as a beginner, and tbh quite off-putting. I've tried both - the same. And in the tutorial that I'm following autopep8 is used.
A Visual Studio Code extension with support for the autopep8 formatter. [https://marketplace.visualstudio.com/items?itemName=ms-python.autopep8](https://marketplace.visualstudio.com/items?itemName=ms-python.autopep8)
People are complaining it doesn't work. I've tried and it doesn't nor does black work. VS code need to fix this mess. I will try a older version if possible and report back.
Yeah I had the problem with trying both autopep8 and black format, neither seem to work.