Juan Christian wrote:
> Using the default json lib is easy and straightforward:
>
> import json
> info = json.loads('file.json')
> # Use dict and list to navigate through 'info'
>
>
> Sadly, I'm working in a script and the only format the server gives is
> XML, I searched for a good alternative and didn't find anything as easy as
> the default json lib.
>
> Any tips?
I have never used it, but lxml.objectify seems pretty intuitive:
>>> from lxml import objectify
>>> a = objectify.fromstring("<a><b foo='bar'>10</b><c>20</c></a>")
>>> a.b
10
>>> a = objectify.fromstring("<a><b foo='bar'>10</b><c>20</c><c>30</c></a>")
>>> a.b
10
>>> a.b**2
100
>>> a.b.get("foo")
'bar'
>>> a.c
20
>>> a.c[1]
30
>>> len(a.c)
2
See <http://lxml.de/objectify.html>
_______________________________________________
Tutor maillist - [email protected]
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor