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

Neil Cerutti horpner at yahoo.com
Thu Oct 19 17:57:15 CEST 2006


On 2006-10-19, Michael Ströder <michael at stroeder.com> wrote:
> 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

No, the setting of the console encoding (sys.stdout.encoding) is
ignored. It's a good thing, too, since it's pretty flaky. It uses
sys.getdefaultencoding(), which is always 'ascii' as far as I
know.


-- 
Neil Cerutti



More information about the Python-list mailing list