Python

IndentationError: unexpected indent

IndentationError

Python uses indentation for block structure. Mixed tabs/spaces or incorrect alignment causes this error.

Common Causes

Fixes

  1. 1. Use spaces consistently (PEP 8: 4 spaces)
    # Configure editor to use 4 spaces, never tabs
  2. 2. Convert tabs to spaces
    expand -t 4 file.py > file_fixed.py
  3. 3. Check block alignment
    def foo():
        if True:
            pass  # same indent level for block

Still not fixed?

Related Errors

DuskTools That Might Help

All Errors