[Biopython] Entrez.read return value is typed as a string??

Ben O'Loghlin bassbabyface at yahoo.com
Thu Oct 29 14:59:45 UTC 2009


Thanks Michiel.

What is the function of the 'u' in the string discussed below? That's the
bit that's got me confused.

Best regards,
Ben

p.s. assistance on this list is fast and useful. Nice!

-----Original Message-----
From: Michiel de Hoon [mailto:mjldehoon at yahoo.com] 
Sent: Thursday, 29 October 2009 2:50 PM
To: 'Peter'; Ben O'Loghlin
Cc: biopython at biopython.org
Subject: Re: [Biopython] Entrez.read return value is typed as a string??



--- On Wed, 10/28/09, Ben O'Loghlin <bassbabyface at yahoo.com> wrote:
> >>>> handle = Entrez.efetch(db="pubmed", id="17206916", retmode="XML")
> >>>> record = Entrez.read(handle)
> >>>> print record
> >[{u'MedlineCitation': ... ]
> 
> I'm interested in using this format, however I don't
> understand how to
> read/write fields and subtrees of the object type
> 'Bio.Entrez.Parser.ListElement' returned by
> Entrez.read(handle) with retmode XML. 
> 
> I'm finding it hard to track down references to this
> [{u'x':['y']}] object format in Python ...

Look at the outermost two brackets [].
You can treat this object as a Python list.

So if record = [{u'x':['y']}],
then record[0] = {u'x':['y']}

Now look at the two outermost braces {}.
You can treat record[0] as a dictionary.
So record[0]['x'] will return ['y'].
Which can then be treated as a Python list.

--Michiel.


      





More information about the Biopython mailing list