-6
#!/usr/bin/python
import os
for x in os.listdir("/home/"):
print x

error: File "./p1", line 4 print x ^ IndentationError: expected an indented block

Python 2.7.12

5
  • 6
    that could be an IndentationError in line 4. at the print statement. where there should be an 'indented block', just what the error message states. what is unclear about that? Commented Feb 14, 2018 at 13:17
  • 1
    What is unclear about that error? You didn't indent print x Commented Feb 14, 2018 at 13:17
  • 2
    python is exactly telling you that in line 4, the instruction print x has an indentation error. It cannot be more specific Commented Feb 14, 2018 at 13:18
  • @LightnessRacesinOrbit I replaced the target with a more relevant one. Commented Feb 14, 2018 at 13:27
  • @PM2Ring: Much better, thanks Commented Feb 14, 2018 at 13:31

1 Answer 1

2

You need to indent your code properly:

import os
for x in os.listdir("/home/"):
    print x
Sign up to request clarification or add additional context in comments.

3 Comments

@SembeiNorimaki: It's just a rendering artefact because Sim used the wrong Markdown.
import os for x in os.listdir("/home/"): print x Thank you
@antony_sebastian ??

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.