[Python-Dev] sys.stdout.write encoding failure (original) (raw)
Amaury Forgeot d'Arc amauryfa at gmail.com
Mon Dec 15 09:47:31 CET 2008
- Previous message: [Python-Dev] sys.stdout.write encoding failure
- Next message: [Python-Dev] Python 3.0 urllib fails with chunked HTTP responses
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Hi,
Alexander Belopolsky wrote:
There is currently a unit test in the trunk that fails in verbose mode:
$ ./python.exe Lib/test/testdoctest.py -v ... UnicodeEncodeError: 'ascii' codec can't encode characters in position 338-339: ordinal not in range(128) Apparently, the problem is that stdout cannot encode non-ascii characters:
sys.stdout.write(u'f\xf6\xf6') Traceback (most recent call last): File "", line 1, in UnicodeEncodeError: 'ascii' codec can't encode characters in position 1-2: ordinal not in range(128) which is strange because sys.stdout.encoding 'UTF-8' and print has no problem with the same string: print u'f\xf6\xf6' föö Where does 'ascii' codec come from?
It's sys.getdefaultencoding default value.
sys.stdout.write() expects a bytes string. What you see here is the coercion of the unicode to a string.
-- Amaury Forgeot d'Arc
- Previous message: [Python-Dev] sys.stdout.write encoding failure
- Next message: [Python-Dev] Python 3.0 urllib fails with chunked HTTP responses
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]