Splitting SAX results
Stefan Behnel
stefan.behnel-n05pAM at web.de
Thu Jun 7 02:44:36 EDT 2007
IamIan wrote:
> I have a very simple SAX script from which I get results like
> 'Title1:Description','Title2:Description'. I want to split each result
> on the colon, using the two resulting elements as key/value pairs in a
> dictionary. I've tried a couple different approaches with lists etc,
> but I keep getting an 'IndexError: list index out of range' when I go
> to split the results. Probably an easy fix but it's my first hack at
> SAX/XML. Thank you!
Sounds like a problem with the data to me rather than SAX.
However, SAX tends to make things much more complex than necessary, so you
loose the sight on the real problems. Try a library like ElementTree or lxml
to make your life easier. You might especially like lxml.objectify.
http://effbot.org/zone/element.htm
http://effbot.org/zone/element-iterparse.htm
http://codespeak.net/lxml/dev/
http://codespeak.net/lxml/dev/objectify.html
Stefan
More information about the Python-list
mailing list