Repeat Python function call on exception?

后端 未结 7 667
抹茶落季
抹茶落季 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 08:13

    Try following snippet:

    while True:
        try:
            func()
            break
        except:
            print "Error. Gonna try again"
    

    But it is better to limit the number of retries.

    0 讨论(0)
提交回复
热议问题