[Biopython] [Entrez] use the handle twice
Peter Cock
p.j.a.cock at googlemail.com
Sat Dec 19 11:06:09 UTC 2015
This is the way network handles work, the server returns
the data to the client computer (your Python code) once
only. As soon as you read it (or Biopython's parser does),
the data is gone.
For small data you can cache it in memory - Biopython
has an UndoHandle we use for this sometimes.
For large data, the best plan is simply to save the data
to a file on disk, then reopen the file for reading and
parse it.
Peter
On Sat, Dec 19, 2015 at 9:59 AM, <c.buhtz at posteo.jp> wrote:
> I want to use the handle returned by Entrez.efetch() twice.
>
> First time, write the xml to a file
>
> f.write(handle._handle.read())
>
> But I want to know how much records are in there.
>
> records = Entrez.read(handle)
> print(records['Count'])
>
> This doesn't work here because the handle is "empty" after the first
> read()-call.
>
> Open an read the xml-file would be a resource wasting workaround and not
> a solution.
> --
> GnuPGP-Key ID 0751A8EC
> _______________________________________________
> Biopython mailing list - Biopython at mailman.open-bio.org
> http://mailman.open-bio.org/mailman/listinfo/biopython
More information about the Biopython
mailing list