Unicode literals to latin-1

Piet van Oostrum piet at cs.uu.nl
Wed Jan 30 04:22:18 EST 2008


>>>>> <David.Reksten at sweco.no> (DR) wrote:

>DR> How can I convert a string read from a database containing unicode literals, such as "Fr\u00f8ya" to the latin-1 equivalent, "Frøya"?
>DR> I have tried variations around
>DR>   "Fr\u00f8ya".decode('latin-1')
>DR> but to no avail.

You have to use encode instead of decode, and the input string must be a
unicode string.

>>> print u"Fr\u00f8ya".encode('latin-1')
Frøya
>>> 


-- 
Piet van Oostrum <piet at cs.uu.nl>
URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C4]
Private email: piet at vanoostrum.org



More information about the Python-list mailing list