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'
• 2,777 views
•
link
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...
• 0 views
•
link
Log in to answer this question.