17

In , indentation is very important:

>>> for i in [1, 2, 3]:
... print(i)

  File "<input>", line 2
    print(i)
        ^
IndentationError: expected an indented block

>>> for i in [1, 2, 3]:
...     print(i)
...     
... 
1
2
3
>>> 

However, questions about the IndentationError have been asked so many times, I want to know how to handle them:

  1. Close as dupe, because questions like them have been asked & answered so many times?

  2. Answer it, because almost every question about indentation is different?


Let's check some examples:

And so on...

5
  • 10
    It is not very clear why you would not consider voting dup when a perfectly good duplicate exists. Is perhaps the real reason that you don't want to dig through 97 dups to find the best one? Well, who does. Just move on. Jan 6, 2016 at 2:44
  • 4
    See Closing as a mental typo. Jan 6, 2016 at 2:47
  • 3
    @Deduplicator: Lol (about that brain fart :P). Well, are you talking about vote to close it as: I'm voting to close this question as off-topic because it's a simple problem which is about the indent. You should try a debugger and check what's wrong and how to fix it. ?
    – Remi Guan
    Jan 6, 2016 at 3:31
  • Really the only indentation error that might deserve its own question is when the error is about matching indentation levels caused by mixing tabs and spaces in the source code in an editor that doesn't display these well. Other than that, they are pretty much all identical and should be easily answerable by a single, canonical source. Jan 7, 2016 at 17:38
  • @Dannnno: Huh, I should answer another question about the indentation problem which has clear title and content (I'll self ask one if it's needed), and use it as dupe target for other questions like it ;)
    – Remi Guan
    Jan 7, 2016 at 20:53

1 Answer 1

12

The example you've created should be considered to be closed as a duplicate since there is a clear error message in the code that would show that the code is affected by the same issue as others.

It gets a bit more difficult with other questions where you need to start doing guesswork to figure out whether the op's just not included the right indentation in their question

if something_equals_true:
    print 1
print 2

You'll often find questions where the op includes a more intricate version of the above where the op only wants to print both if something is true in which case pointing to a duplicate won't really help much. Now you could possibly vtc as a typographical error but you very often struggle to find 4 like minded people so its kind of based off your own opinion whether or not you think it deserves an answer.

0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .