[Python-Dev] Python 3.0.1 (io-in-c)

Paul Moore p.f.moore at gmail.com
Wed Jan 28 19:20:08 CET 2009


2009/1/28 "Martin v. Löwis" <martin at v.loewis.de>:
>>>>> print(open("a1").read())
>> Traceback (most recent call last):
>>   File "<stdin>", line 1, in <module>
>>   File "D:\Apps\Python30\lib\io.py", line 1491, in write
>>     b = encoder.encode(s)
>>   File "D:\Apps\Python30\lib\encodings\cp850.py", line 19, in encode
>>     return codecs.charmap_encode(input,self.errors,encoding_map)[0]
>> UnicodeEncodeError: 'charmap' codec can't encode character '\u0153' in
>> position 1: character maps to <undefined>
>
> Looks right to me.

I don't see why. I wrote the file from the console (cp850), read it in
Python using the default encoding (which I would expect to match the
console encoding), wrote it to sys.stdout (which I would expect to use
the console encoding).

How did the character end up not being encodable, when I've only used
one encoding throughout? (And if my assumptions about the encodings
used are wrong at some point, that's what I'm suggesting is the
error).

Paul.


More information about the Python-Dev mailing list