Python Formatting

Hello,

I’m following the recent Python Tutorial for Beginners (with mini-projects). So my settings are set up just as Dave’s at 29:25, I did everything just like him (except I’m on Mac and not Windows), and when I save or try to manually format the document it isn’t formatting anything, nothing changes. Can someone please help?

1 Like

Can you clarify what you mean by “manually format”?

1 Like

right click/control and ‘Format Document’ or ‘Format Document With…’ where I then pick python for the latter
sorry for confusion

Here is the video for reference: https://youtu.be/qwAFL1597eM?t=1476

Did you install the “Python VS Code extension” from Microsoft? And if you select ‘Format Document With…’ does it give you the option for ‘Python’ under “Select Formatter?”

In this video he also shows how to display the settings json file. Can you copy the contents of that here (Or just check under the Python section?)

addendum: maybe even just skip this part, not a huge fan of installing an auto-formatter first thing in a beginner’s course about Python where formatting is so important, in fact a major feature of the language

Yes, I have the extension and python does come up when I do “Format with…”. Also copied his settings.json file.

When would you recommend to start using auto formatting?

Nothing changes when you select “format with Python” ? Do you definitely have formatting problems? Is it possible it’s already correctly formatted?

Yes nothing changes.
I did the same thing as Dave in the video and put an indentation where there shouldn’t be one, and when I save or format with python, nothing changes like it does for him

Try removing and re-installing the Python VS Code extension.

The good news is, it won’t stop you from completing anything :+1: I think you will just learn Python formatting better

hmm re-installing doesn’t seem to work:( thank you for the tips tho, and good to know this can help me learn better!

1 Like

Hi, Ive just had the same issue. Im not sure how its successfully removing the spaces before line04 in Daves example, when I try it does nothing. It also prompts to use either Black or autopep8 as the formatter. I ended up installing Black and setting that as the default. Opening the Output window for Black I could see it complaining “Skipping non python code”. Basically the formatter is working but it’s not seeing the spaces before line04 in Daves example as python code so its doing nothing. If you were to put a bunch of spaces between ‘line04 =’ and “*****” it will reformat ok.

Cheers.

I am also encountering the same issue. Both autopep8 and black formatter does not work.

For all of these issues re: Microsoft Python for VSCode and Black Python formatter I would check these docs or support sites:

https://github.com/microsoft/vscode-python/discussions/categories/q-a

https://github.com/Microsoft/vscode-black-formatter/issues

https://marketplace.visualstudio.com/items?itemName=ms-python.black-formatter

Could also try installing a different auto-formatter

Hi, this is Dave from the video. :wave: The latest versions of VS Code no longer support the auto-formatting I demonstrated. That said, I did the research, and if you want this formatting behavior, I show you how to get it back here: How to Auto-Format Unwanted Python Line Indentations in VS Code | Dave Gray

Hey please im having the same problem been stuck on it for a month, have reinstalled vscode multiple times and followed multiple tutorials to try and activate it , eventually installed black formatter and autopep8 but nothing is working tried so many stuff , please do you know any work arounds

Please open a new topic for your question