strange behaviour of str()



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
.



Relevant Pages

  • Re: Calling external app from C++
    ... str += szOutput; ... Instead I get the message on console and it doesn't fail as ...
    (comp.unix.programmer)
  • Calling external app from C++
    ... str += szOutput; ... Instead I get the message on console and it doesn't fail as ...
    (comp.unix.programmer)
  • Re: seeking for the good pattern in preg_match
    ... to work with $testing="DDCA" (it passed but it's supposed to fail). ... understand that you test first if each character is in $str but what's ... is removes the first occurrence of $c from $str. ... For each character in $testing: ...
    (comp.lang.php)