<p>我有一个以<code>for i in range(0, 100)</code>开头的循环。正常情况下,它运行正常,但有时由于网络状况而失败。目前,我已经设置了它,因此在失败时,它将<code>continue</code>在except子句中(继续下一个<code>i</code>的数字)。</p>
<p>我是否可以将同一个数字重新分配给<code>i</code>,并再次运行循环的失败迭代?</p>
<p>在for循环中执行<code>while True</code>,将<code>try</code>代码放入其中,并且仅当代码成功时才从该<code>while</code>循环中断。</p>
<pre><code>for i in range(0,100):
while True:
try:
# do stuff
except SomeSpecificException:
continue
break
</code></pre>