[BioPython] NCBIXML - Blast in- and output
Michiel de Hoon
mdehoon at c2b2.columbia.edu
Thu Nov 29 00:02:17 UTC 2007
Björn Thorwirth wrote:
> But shouldn't that beeing catched? And btw. in my first post to the
> list, i asked, if I just should catch the Exception.
> in my code i called the NCBIXML like this:
> try:
> records=NCBIXML.parse(resultFileHandle)
> except Exception,e:
> self.IoErrorHandler(e, resultFileHandle, err_handle)
> raise
> ...
> if records:
> for record in records:
> Thats where i got the Exception. For me is it ok.. I've just added an
> Exception handler around the "for record"-Loop, and everything is done.
> But i thought i schould get the exception by initialization.
>
The NCBIXML.parse call does not actually parse the file, it just sets up
the parser. The actual parsing is done when you call records.next(),
which is done implicitly in your for-loop. This approach allows
NCBIXML.parse to be used also for very large Blast output files, which
cannot be kept in memory as a whole. So the Exception handler should be
around the for-loop, not the parse.
--Michiel.
More information about the Biopython
mailing list