> > 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 >
This does not work, because you need an encoder to convert unicode to str. str() does not know a priori which encoder to use. There are many ways to encode a unicode string to a classic byte-stream based string. you have to procede as follows: >>> s=u"äää" >>> print s.encode("latin-1") äää try "utf-8" and "utf-16" instead of "latin-1" Greetings, Uwe.
-- http://mail.python.org/mailman/listinfo/python-list