Question: TypeError: 'generator' object is unsubscriptable in biopython
0
gravatar for bio90029
2.5 years ago by
bio9002910
bio9002910 wrote:

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.2k views
ADD COMMENTlink modified 2.5 years ago by WouterDeCoster42k • written 2.5 years ago by bio9002910
1
gravatar for WouterDeCoster
2.5 years ago by
Belgium
WouterDeCoster42k wrote:

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...

ADD COMMENTlink modified 2.5 years ago • written 2.5 years ago by WouterDeCoster42k
Please log in to add an answer.

Help
Access

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 1822 users visited in the last hour