Unicode literals to latin-1

Gabriel Genellina gagsl-py2 at yahoo.com.ar
Wed Jan 30 08:30:46 EST 2008


On 30 ene, 07:54, <David.Reks... at sweco.no> wrote:
> On 30. januar 2008 10:48, Marc 'BlackJack' Rintsch wrote:
>
> >On Wed, 30 Jan 2008 09:57:55 +0100, David.Reksten wrote:
>
> >> How can I convert a string read from a database containing unicode
> >> literals, such as "Fr\u00f8ya" to the latin-1 equivalent, "Frøya"?

> >In [388]: 'Fr\u00f8ya'.decode('unicode-escape')
> >Out[388]: u'Fr\xf8ya'
>
> 'unicode-escape' did the trick! Thank you!

A unicode-escaped string looks very strange in a database... I'd
revise the way things are stored and retrieved.

--
Gabriel Genellina



More information about the Python-list mailing list