Biopython 脚本不工作,它发送错误类型生成器

Biopython script is not working, it sends errortype generator

我在尝试使用 biopython 解析 xml 文件时遇到一些我不明白的错误,请问有人能帮我理解吗?

TypeError: object of type 'generator' has no len()

    from Bio import SearchIO
    blast_qresults=SearchIO.parse('my_file.xml', 'blast-xml')
    len(blast_qresults)

    or

    blast_qresults.hit

AttributeError: 'generator' object has no attribute 'hit

我相信这就是您想要的语法:

from Bio import SearchIO

blast_qresults = SearchIO.parse('my_file.xml', 'blast-xml')

for hit in blast_qresults:
    print(hit)

因为 blast_qresults 是一个生成器,你只能 "walk" 它一次。