Repeat Python function call on exception?

后端 未结 7 686
抹茶落季
抹茶落季 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

    success = False
    attempts = 0
    while not success and attempts < 10: # or however many times you want to attempt
        try:
            functionCall()
            success = True
        except:
            i += 1
    if not success:
        raise functionCallFailedError
    

    Hope this helps

提交回复
热议问题