String encode() method error handling options?

M.-A. Lemburg mal at lemburg.com
Tue Jun 19 15:51:53 EDT 2001


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.

> When doing encode('latin-1') on unicode strings received via
> COM/MAPI, I occasionally get a value error.  When I look at the
> message with Outlook there's nothing obviously strange about
> the text.  I forgot to save an example that causes the error,
> so I don't currently have any way to experiment.

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.

-- 
Marc-Andre Lemburg
CEO eGenix.com Software GmbH
______________________________________________________________________
Company & Consulting:                           http://www.egenix.com/
Python Software:                        http://www.lemburg.com/python/




More information about the Python-list mailing list