convert strings to utf-8

Diez B. Roggisch deets at nospam.web.de
Sun Feb 25 17:10:47 EST 2007


Niclas schrieb:
> Thank you!
> 
> solved it with this:
>  unicode( data.decode('latin_1') )

The unicode around this is superfluous. Either do

unicode(bytestring, encoding)

or

bytestring.decode(encoding)


> and when I write it to the file...
>         f = codecs.open(path, encoding='utf-8', mode='w+')
>         f.write(self.__rssDoc.toxml())


Looks good, yes.

Diez



More information about the Python-list mailing list