I\'m trying to create an application in Python 3.2 and I use tabs all the time for indentation, but even the editor changes some of them into spaces and then print out \"inc
If you are using Sublime Text for Python development, you can avoid the error by using the package Anaconda. After installing Anaconda, open your file in Sublime Text, right click on the open spaces → choose Anaconda → click on autoformat. Done. Or press Ctrl + Alt + R.
Sometimes, tab
does mess up while indenting. One way is to obviously use the tab
and backspace
to correctly indent the code.
Another way is to use space
4 times (depending on how much you want to indent).
A weird way that worked for me when nothing else worked, whichever line I getting the error, I backspaced
that line to the previous line and then pressed enter
. It automatically indented the line to correct position and I was not getting any error after that.
Hopefully, this should help.
Use pylint
it will give you a detailed report about how many spaces you need and where.
I had the same error. I had to add several code lines to an existing *.py file. In Notepad++ it did not work.
After adding the code lines and saving, I got the same error. When I opened the same file in PyCharm and added the lines, the error disappeared.
I got the same errors but could not figure out what I was doing wrong.
So I fixed it by running auto-indent on my code and allowing the machine to fix my fault.
If anyone is wondering how I did that. Simple. Go in vim. Type in G=gg.
This will automatically fix everything. Good luck :)
Don't use tabs.
Note: The reason for 8 spaces for tabs is so that you immediately notice when tabs have been inserted unintentionally - such as when copying and pasting from example code that uses tabs instead of spaces.