An IndentationError
occurs most frequently when indenting code with a mixture of spaces or tabs. It is preferred to indent your code with four spaces rather than a tab character. You can check for tabs and spaces in most text editors by showing all symbols or run the -tt
flag with Python to identify troublesome lines (that is, if you're script doesn't report the exception in the first place). Once you select an editor of your liking, be sure to configure it to uniformly place spacing throughout your script.
Another common source of this error is failing to match the appropriate indentation level within your script. For example, in lengthier code segments you might mistakenly indent some line of code with too few spaces or tabs:
>>> def indentation(): ... print 'Good indentation' ... print 'Bad indentation' File "<stdin>", line 3 print "Bad indentation" ^ IndentationError: unindent does not match any outer indentation level