Repeat Python function call on exception?

后端 未结 7 673
抹茶落季
抹茶落季 2021-02-08 07:48

Hey everybody I\'m working on a data scraping project and I\'m looking for a clean way to repeat a function call if an exception is raised.

Pseudo-code:

         


        
7条回答
  •  灰色年华
    2021-02-08 07:51

    Use a loop

    i = 0
    while True:
      try: myfunc(x); break;
      except myError:
        i = i + 1;
        # print "Trying again"
        if i > 5: raise myError2;
    

提交回复
热议问题