Macos – Visual Studio Code Python Indentation Issues

macosmacos-mojavepythonpython3visual-studio-code

So I have been having issues with my VSC and python 3.7
It works when I try to run the code through Sublime and terminal, and seems to fix itself after I restart visual studio, but always returns within 10 minutes or so.

When i write code in python, automatic indents are not correct. The program as well as compiler, when I try to run it in terminal, complain about it. (As seen in picture 1) However, even when I try to manually change it to the correct position, compiler and VSC complain and do not let me compile it because of unexpected indentation. (As seen in picture 2)

I have reinstalled VSC a few times because of this issue, I have freshly reinstalled macOS Mojave, and I have reinstalled python 3.7 and extensions for VSC. The problem resolves itself for a little bit if I restart the program, but I would rather not have to restart the program every other time I need to indent things in python (where indentation is rather critical)

When my brother, who is a windows user, copies my code to his VSC, it does not show the same issue, so I'm completely lost as to what to do.

how VSC indents the code automatically

how VSC behaves when i fix indentation manually

Best Answer

There are some Text Editor settings which control the indentation, just check File > Preferences > Settings and search for "Indent"

Intend settings part 1 Intend settings part 2

Plus in the bottom right corner you can see and change the setting for the document currently working on, just click on it

Intend settings per document

I assume this is wrong and shows something different than 4. If you are working mostly in python, perhaps it would make sense to set the default to 4 in the general settings?

Related Question