1

So I have this code snippet from a Python3 script, which sadly produces a "expected indented block" error. The usual answer seems to be that you either indented wrong or mixed tabs and spaces. I checked both of those but my intendation seems fine and I am only using 4 spaces to indent, no tabs. Anyone got an Idea whats wrong?

for submission in submissions:
    currentUser = submission.author.name
    if currentUser in uniqueUsers:
        # Do Nothing
    else:
        uniqueUsers.append(currentUser)

for user in uniqueUsers:
    print(user)
jns
  • 99
  • 1
  • 1
  • 8

3 Answers3

0

You can use pass keyword whenever you don't want to do anything

for submission in submissions:
    currentUser = submission.author.name
    if currentUser in uniqueUsers:
        pass
        # Do Nothing
    else:
        uniqueUsers.append(currentUser)

for user in uniqueUsers:
    print(user)
0

You need to write pass insted of the Do nothing

for submission in submissions:
    currentUser = submission.author.name
    if currentUser in uniqueUsers:
        pass
    else:
        uniqueUsers.append(currentUser)

for user in uniqueUsers:
    print(user)
Tejas Thakar
  • 585
  • 5
  • 19
0

If # Do Nothing actually doesn't do anything, this should work:

for submission in submissions:
    currentUser = submission.author.name
    if not currentUser in uniqueUsers:
        uniqueUsers.append(currentUser)

for user in uniqueUsers:
    print(user)

Or as other people mentioned, you can also use the keyword pass.

Silveris
  • 1,048
  • 13
  • 31
  • 1
    `currentUser not in uniqueUsers` is a single expression using the two-word `not in` operator, rather than having to negate the result of `currentUser in uniqueUsers`. – chepner Jul 12 '17 at 18:42