Python 3中的意图错误

时间:2017-07-12 12:20:22

标签: python python-3.x if-statement

所以我有一个来自Python3脚本的代码片段,遗憾地产生一个"预期的缩进块"错误。通常的答案似乎是缩进错误或混合制表符和空格。我检查了这两个,但我的意图似乎很好,我只使用4个空格缩进,没有标签。 任何人都有一个想法是错的吗?

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

for user in uniqueUsers:
    print(user)

3 个答案:

答案 0 :(得分:0)

只要您不想做任何事情,就可以使用传递关键字

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)

答案 1 :(得分:0)

您需要撰写pass

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)

答案 2 :(得分:0)

如果# Do Nothing实际上没有做任何事情,那么这应该有效:

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

for user in uniqueUsers:
    print(user)

或者正如其他人提到的那样,您也可以使用关键字pass