# How to prevent indentation errors?

I added a line and am very sure there is no indentation problem. Here is the error report and screenshots of the text so you can see it:

Error: File "C:\Users\info\Desktop\Claas UI.blend\Claas_UI_2.py", line 40 bpy.ops.object.mode_set( mode = 'EDIT' )

TabError: inconsistent use of tabs and spaces in indentation location: :-1

Error: Python script fail, look in the console for now...

When I remove the line with the arrows and uncoment the previous lines below it all runs fine.

Any idea what causes this?

Python doesn't like inconsitently mixed tabs and spaces for indentation.

Ctrl-T opens the property panel, check that the Tabs as Spaces is ticked.

You can usually fix this by unindenting the lines in question by Shift-Tab to the first column and re-indent them Tab again.

There is also the menu option available Format > Convert Whitespace > To Spaces (or to tabs)

Related:

• This is rather bizarre. I use tabs from the beginning and not spaces. So I reset all tab steps and then formatted the text again. It worked. Must have by accident adjusted some text via spaces. Jan 6 '16 at 13:07

Recently I faced a similar problem. I was using the sublime editor. it's not an issue with the code but with the editor.

Below change in the preference settings worked for me.

Sublime Text menu -> Preferences -> Settings: Syntax-Specific:

{ "tab_size": 4, "translate_tabs_to_spaces": true }

That error was driving me crazy. To solve on Visual Studio Code. Click with mouse right button, and select Command Palette on your code, and after that select de command 'Convert Indentation to Tabs'