WestCoastProjects
WestCoastProjects

Reputation: 63022

Pycharm sometimes does not indent the proper amount

I have tabs and indents|indent set to 2:

enter image description here

However the actual indentation is coming up as 3 - specifically inside the groupby function - which I have unindented and re-indented several times to be sure the behavior were consistent[-ly incorrect]:

enter image description here

Note that I have also tried the Auto-indent (Option-Command-I) - it also indents stuff to 3 spaces instead of 2. Bit strange..

Any thoughts?

Upvotes: 2

Views: 2789

Answers (2)

Tarun Gandotra
Tarun Gandotra

Reputation: 51

This is most annoying problem in pycharm. Here is simple answer to this :

Just follow the path :

GO to Edit->Convert Indents->To Spaces

This will actually insert space instead of tabular character in empty space when you default enter for next line.

Upvotes: 2

JoshG
JoshG

Reputation: 6735

The first thing you might want to check is to make sure you don't have Detect and use existing file indents for editing enabled in Settings/Preferences | Editor | Code Style. If you do, when you auto-indent, it might apply the wrong settings.

You can try to fix incorrectly formatted code by using Option+Command+L (Mac) / Control+Alt+L (PC), which is the Reformat Code option. That should fix the code and then auto-indent should work correctly.

Upvotes: 8

Related Questions