【发布时间】:2016-03-09 21:21:34
【问题描述】:
当我输入此代码时,我得到“IndexError: list is out of range”。此外,retmax 设置为 614,因为这是我提出请求时的结果总数。有没有办法使用根据搜索结果而变化的变量使 retmode 等于结果数?
#!/usr/bin/env python
from Bio import Entrez
Entrez.email = "something@gmail.com"
handle1 = Entrez.esearch(db = "nucleotide", term = "dengue full genome", retmax = 614)
record = Entrez.read(handle1)
IdNums = [int(i) for i in record['IdList']]
while i >= 0 and i <= len(IdNums):
handle2 = Entrez.esearch(db = "nucleotide", id = IdNums[i], type = "gb", retmode = "text")
record = Entrez.read(handle2)
print(record)
i += 1
【问题讨论】:
-
我打错了:handle2的定义有一个and括号。
-
请更新您的代码以反映您所做的更改 -- 然后我们可以从那里开始。
-
好的,我刚刚修正了错字。但我仍然遇到 for 循环与 IdNums[i] 交互的越界错误问题。