Else Syntax Error Python

后端 未结 6 1927
心在旅途
心在旅途 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 07:08

    You can do else with for loops in Python, but you'll need to balance your parentheses on:

    log_f.write("Name:%s \n Email: %s" % (name, email)
    

    which should actually be

    log_f.write("Name:%s \n Email: %s" % (name, email))
    

    (Note the extra final parenthesis.)

提交回复
热议问题