How to get back to the for loop after exception handling

后端 未结 3 1870
南笙
南笙 2021-01-30 22:39

I am ready to run this code but before I want to fix the exception handling:

for l in bios:
    OpenThisLink = url + l
    try:
        response = urllib2.urlope         


        
3条回答
  •  北荒
    北荒 (楼主)
    2021-01-30 23:22

    Use continue instead of break.

    The statement pass is a no-op (meaning that it doesn't do anything). The program just continues to the next statement, which is why you get an error.

    break exits the loops and continues running from the next statement immediately after the loop. In this case, there are no more statements, which is why your program terminates.

    continue restarts the loop but with the next item. This is exactly what you want.

提交回复
热议问题