Forum

Author Topic: IndentationError: expected an indented block  (Read 2868 times)

Jean_Rodriguez

  • Newbie
  • *
  • Posts: 1
    • View Profile
IndentationError: expected an indented block
« on: March 22, 2021, 06:10:30 PM »
Hi,
i'm trying to run a python script but i have this message:

IndentationError: expected an indented block
Error: expected an indented block (D:/code_python/script1.py, line 28)

In my code, the line 28 is: print("""/!\ ATTENTION /!\ : aucun chemin d'enregistrement fourni !""")

26: project_path = PhotoScan.app.getSaveFileName("D:\09._Rapport de stage\code_python\Project_mobile.psx")
27: if not project_path:
28: print("""/!\ ATTENTION /!\ : aucun chemin d'enregistrement fourni !""")
29: if project_path[-4:].lower() != ".psx":
30: project_path += ".psx"


Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14855
    • View Profile
Re: IndentationError: expected an indented block
« Reply #1 on: March 22, 2021, 07:05:44 PM »
Hello Jean,

You are missing indentation (leading "tab" or fixed number of "spaces") in the lines 28 and 30.

See:
https://docs.python.org/2.0/ref/indentation.html
Best regards,
Alexey Pasumansky,
Agisoft LLC

walshmagger

  • Newbie
  • *
  • Posts: 2
    • View Profile
Re: IndentationError: expected an indented block
« Reply #2 on: April 13, 2023, 07:59:04 AM »
This error usually occurs in Python code and it means that there is a problem with the indentation of the code. In Python, indentation is used to indicate the scope of control structures like loops, functions, and conditional statements.

Ensuring proper indentation is crucial to avoid error messages. Forgetting to indent statements within a compound statement or a user-defined function are common causes of IndentationError: expected an indented block. The error message suggests an issue with indentation, which could be due to a mix of tabs and spaces. To avoid issues, it is recommended to use four spaces for indentation in Python. While tabulation or a different number of spaces may work, they may cause problems. Tabs are not recommended because they can create inconsistent spacing in different editors.