我正在處理代碼,但我不太確定當涉及try-except塊時,代碼是如何精確流經循環的。代碼如下:循環流,除嘗試塊外
while len(usernames)>0:
for username in usernames:
while current_count<aimed_count:
try:
"""processing stuff"""
except error:
if:
if:
#handle it
else:
usernames.remove(username)
else:
usernames.remove(username)
usernames.remove(username)
現在,如果我抓住通過進入一個錯誤兩者如果在錯誤語句塊,我想我的代碼繼續回到try塊的開始,我相信它(希望如此沒有問題)。如果我捕獲到except塊中的其他語句的錯誤,則代碼將無法返回嘗試阻止,因爲用戶名不再存在。那麼,如何確保代碼在這兩種情況下的第一個while循環中開始?我應該在兩個陳述之後放置一個break語句嗎?
try/except無關緊要,重要的是不要更改正在迭代的列表。 – RemcoGerlich