問題:
I have a loop starting with for i in range(0, 100)
.我有一個以for i in range(0, 100)
開頭的循環。 Normally it runs correctly, but sometimes it fails due to network conditions.通常它運行正常,但有時會由於網絡條件而失敗。 Currently I have it set so that on failure, it will continue
in the except clause (continue on to the next number for i
).目前我已經設置了它,以便在失敗時,它將continue
在 except 子句中(繼續到i
的下一個數字)。
Is it possible for me to reassign the same number to i
and run through the failed iteration of the loop again?我是否可以將相同的數字重新分配給i
並再次運行失敗的循環迭代?
解決方案:
參考一: https://stackoom.com/question/8k8h參考二: How to retry after exception?