String encode() method error handling options?
Grant Edwards
grante at visi.com
Tue Jun 19 16:56:08 EDT 2001
In article <mailman.992980410.25808.python-list at python.org>, M.-A. Lemburg wrote:
>Grant Edwards wrote:
>>
>> The documentation for the encode() method mentions that the
>> default action for an encoding error is to raise ValueError.
>> The other options are 'ignore' and 'replace'. Can anybody
>> point me to documentation on or examples of the ingore and
>> replace options?
>
>The 'ignore' option will simply drop the character which cannot
>be encoded (e.g. because there is no mapping for the Unicode
>character in the chosen character set), the 'replace' option
>will currently always write a '?' instead of the Unicode character
>which caused the trouble.
Thanks! Next time it happens I'll try using 'replace' and see
what characters are causing the problem.
>Latin-1 is not the same as the default Windows encoding which
>typically is one of the cp125x encodings depending on your locale.
>That could be the cause of the ValueErrors you are seeing.
I'm sure you're right. Latin-1 seems to support enough of the
local Windows encoding that I very rarely see the problem.
--
Grant Edwards grante Yow! I decided to be JOHN
at TRAVOLTA instead!!
visi.com
More information about the Python-list
mailing list