UTF-8 to unicode or latin-1 (and yes, I read the FAQ)

Michael Ströder michael at stroeder.com
Thu Oct 19 14:46:26 CEST 2006

NoelByron at gmx.net wrote:
> print 'K\xc3\xb6ni'.decode('utf-8')
> and this line raised a UnicodeDecode exception.

Works for me.

Note that 'K\xc3\xb6ni'.decode('utf-8') returns a Unicode object. With
print this is implicitly converted to string. The char set used depends
on your console

Check this out for understanding it:

>>> u = 'K\xc3\xb6ni'.decode('utf-8')
>>> s=u.encode('iso-8859-1')
>>> u
>>> s

Ciao, Michael.

More information about the Python-list mailing list