This is a test version of Biostars. For the public version, visit https://www.biostars.org.
TypeError: 'generator' object is unsubscriptable in biopython

Can anyone help me to find the error on this, please? I am trying to count the numbers of hit in an xml file but I get the above errors:

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'
biopython

1 answer

Try with len(list(blast_qresults)).
A generator doesn't have an apriori known length, you'll first need to convert it to a list. Although that's not as memory efficient...

Log in to answer this question.