Else Syntax Error Python

后端 未结 6 1926
心在旅途
心在旅途 2020-12-07 06:27
if len(user_hash) > 0:
  with open(log_file, \"w\") as log_f:
    for name in user_hash:
        log_f.write(\"Name:%s \\n Email: %s\" % (name, email)

    else l         


        
6条回答
  •  猫巷女王i
    2020-12-07 06:59

    You can't supply a condition with an else statement. else means "everything else" --- that is, everything else but whatever conditions you specified in an earlier if. It's not clear what you're trying to accomplish with that else, but perhaps you mean it to be an if.

    It could also be an elif ("else if"), but if you mean it to be an else for the earlier if clause, then you need to unindent it so it's at the same indentation level as the if. An if and it's else/elif have to line up at the same indentation level.

    (There is such a thing as an else clause for a for statement, but it doesn't look like that's what you want here.)

提交回复
热议问题