>From python manual str( [object])
Return a string containing a nicely printable representation of an object. For strings, this returns the string itself. The difference with repr(object) is that str(object) does not always attempt to return a string that is acceptable to eval(); its goal is to return a printable string. If no argument is given, returns the empty string, ''. now we try this under windows: >>> str(u'\ue863') Traceback (most recent call last): File "<stdin>", line 1, in <module> UnicodeEncodeError: 'ascii' codec can't encode character u'\ue863' in position 0 : ordinal not in range(128) FAIL. also almighty Linux Python 2.3.4 (#1, Feb 6 2006, 10:38:46) [GCC 3.4.5 20051201 (Red Hat 3.4.5-2)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> str(u'\ue863') Traceback (most recent call last): File "<stdin>", line 1, in ? UnicodeEncodeError: 'ascii' codec can't encode character u'\ue863' in position 0: ordinal not in range(128) Python 2.4.4 (#2, Apr 5 2007, 20:11:18) [GCC 4.1.2 20061115 (prerelease) (Debian 4.1.1-21)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> str(u'\ue863') Traceback (most recent call last): File "<stdin>", line 1, in ? UnicodeEncodeError: 'ascii' codec can't encode character u'\ue863' in position 0: ordinal not in range(128) Python 2.5 (release25-maint, Jul 20 2008, 20:47:25) [GCC 4.1.2 20061115 (prerelease) (Debian 4.1.1-21)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> str(u'\ue863') Traceback (most recent call last): File "<stdin>", line 1, in <module> UnicodeEncodeError: 'ascii' codec can't encode character u'\ue863' in position 0: ordinal not in range(128) The problem is, why the f**k set ASCII encoding to range(128) ???????? while str() is internally byte array it should be handled in range(256) !!!!!!!!!! http://bugs.python.org/issue3648 One possible solution(Windows Only) >>> str(u'\ue863'.encode('mbcs')) '\xfe\x9f' >>> print u'\ue863'.encode('mbcs') �� I now spending 60% of my developing time dealing with ASCII range(128) errors. It was PAIN!!!!!! Please fix this issue. http://bugs.python.org/issue3648 Please.
-- http://mail.python.org/mailman/listinfo/python-list