Indentation troubleshooting (IndentationError, TabError)
- indentation
- tabs
Indentation errors are a common beginner issue when first learning to program in Python.
How to fix each error depends on the specifics of the case. The canonical indentation errors post covers them all.
The specific errors covered:
IndentationError: unexpected indentIndentationError: expected an indented blockTabError: inconsistent use of tabs and spaces in indentationSyntaxErrorfor continuation of a compound statement that was broken up by lack of indentation (e.g.else:no longer connected toiforfororwhile, etc.).
The post includes an intro, treatise on tabs vs spaces, and addresses each of the possible errors in turn.
Fixes include adding a body to compound statements (including pass), matching indentation levels, checking for mixed use of tabs and spaces.