How to get back to the for loop after exception handling

后端 未结 3 1869
南笙
南笙 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:14

    you are getting that error because when the exception is thrown the response variable doesn't exist. If you want to leave the code how you have it you will need to check that response exists before calling read

    if response:
        bio = response.read()
        ...
    

    having said that I agree with Mark that continue is a better suggestion than pass

提交回复
热议问题