当使用BioPython时,函数不会遍历整个列表

2024-09-30 22:20:52 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试使用从CSV文件派生的搜索词搜索PubMed。我将搜索词组合成一种可以被Biopython的Entrez模块理解的形式,如下所示:

term1 = ['"' + name + " AND " + disease + '"' for name, disease in zip(names, diseases)]

其中“名称”和“疾病”指的是我正在使用eSearch组合到搜索中的参数。 随后,为了执行搜索,我编写了以下代码:

from Bio import Entrez
Entrez.email = "theofficialvelocifaptor@gmail.com"
for entry in range(0, len(term1)):
 handle = Entrez.esearch(db="pubmed", term=term1[entry], retmax="10")
 record = Entrez.read(handle)
 record["IdList"]
 print("The first 10 are\n{}".format(record["IdList"]))

现在,我希望从代码中得到的是,在term1中存储的整个列表上迭代函数。然而,这是我得到的输出:

['Botanical name', 'Asystasia salicifalia', 'Asystasia salicifalia', 'Asystasia salicifalia', 'Barleria strigosa', 'Justicia procumbens', 'Justicia procumbens', 'Strobilanthes auriculata', 'Thunbergia laurifolia', 'Thunbergia similis']
['Disease', 'Puerperal illness', 'Puerperium', 'Puerperal disorder', 'Tonic', 'Lumbago', 'Itching', 'Malnutrition', 'Detoxificant', 'Tonic']
The first 10 are
['31849133', '31751652', '31359527', '31178344', '31057654', '30725751', '28476677', '27798405', '27174082', '26923540']
The first 10 are
[]
The first 10 are
[]
The first 10 are
[]
The first 10 are
[]
The first 10 are
[]
The first 10 are
The first 10 are
[]
The first 10 are
[]
The first 10 are
[]

当然,我遗漏了一些东西,因为迭代似乎过早地缩短了。在我写作的时候,我已经花了整整5个小时,我觉得自己很傻。我还应该提到,我是Python新手,所以如果我犯了任何明显的错误,我都看不到


Tags: theterm1代码nameinforentrezrecord