Odd unicode() behavior

maport at googlemail.com maport at googlemail.com
Wed Aug 30 06:29:10 EDT 2006


The behavior of the unicode built-in function when given a unicode
string seems a little odd to me:

>>> unicode(u"abc")
u'abc'

>>> unicode(u"abc", "ascii")
Traceback (most recent call last):
File "<stdin>", line 1, in ?
TypeError: decoding Unicode is not supported

I don't see why providing the encoding should make the function behave
differently when given a Unicode string. Surely unicode(s) ought to
bahave exactly the same as unicode(s,sys.getdefaultencoding())?

Any opinions?

Mike.




More information about the Python-list mailing list