strange behaviour of str()

Juho Vuori juho.vuori at helsinki.fi
Wed Aug 31 12:20:21 CEST 2005


Hello,

I'm wondering about the following behaviour of str() with strings 
containing non-ASCII characters:

str(u'foo') returns 'foo' as expected.

str('lää') returns 'lää' as expected.

str(u'lää') raises UnicodeEncodeError

Is this behaviour sane? Possibly, but not documented at all. Somehow 
you'd expect str() to never fail. I'm hesitating about sending a bug 
report about a third party application, which fails because it is 
relaying on this.

Cheers,
Juho Vuori



More information about the Python-list mailing list