【发布时间】:2020-11-08 15:49:56
【问题描述】:
我有一个 ID 为字符串格式 (list_id) 的列表。我创建了一个数字从 1 到 list_id 长度的双端队列 (de_list_id),这样我就可以引用 list_id 的每个元素。 此外,我还有一个功能可以检查文件(带有特定 ID)是否在线备份。我希望循环重复,直到一切都在线。我写道:
while de_list_id:
k = de_list_id.popleft() #take the first element and check if it is online
status = check(arg1, arg2, list_id[de_list_id[k]], arg3)
if status:
dl_routine(arg1, arg2, list_id[de_list_id[k]], arg3) # if so, download and remove
else:
de_list_id.append(k) # if not, append it back to list
但是返回:
IndexError:双端队列索引超出范围
有谁知道为什么以及如何解决这个问题?任何帮助将非常感激。提前致谢!
【问题讨论】:
-
你的代码缩进真的像你的问题,
if块在循环之外吗? -
抱歉,当然不是。我编辑了。
标签: python while-loop deque