xml.parsers.expat and utf-8

Kent Johnson kent37 at tds.net
Tue May 3 22:00:13 EDT 2005


dagurp at gmail.com wrote:
> I have this code:
> 
> import xml.parsers.expat
> parser = xml.parsers.expat.ParserCreate(encoding="UTF-8")
> text = unicode("<div>þórður</div>",'UTF-8')

I think you want
   text = u"<div>þórður</div>".encode('UTF-8')
so text is a UTF-8 string.

Kent



More information about the Python-list mailing list