[Python-checkins] cpython (3.3): document UnicodeError attributes

benjamin.peterson python-checkins at python.org
Sun Dec 2 17:33:26 CET 2012


http://hg.python.org/cpython/rev/221858c0d3b1
changeset:   80694:221858c0d3b1
branch:      3.3
user:        Benjamin Peterson <benjamin at python.org>
date:        Sun Dec 02 11:33:06 2012 -0500
summary:
  document UnicodeError attributes

files:
  Doc/library/exceptions.rst |  24 ++++++++++++++++++++++++
  1 files changed, 24 insertions(+), 0 deletions(-)


diff --git a/Doc/library/exceptions.rst b/Doc/library/exceptions.rst
--- a/Doc/library/exceptions.rst
+++ b/Doc/library/exceptions.rst
@@ -371,6 +371,30 @@
    Raised when a Unicode-related encoding or decoding error occurs.  It is a
    subclass of :exc:`ValueError`.
 
+   :exc:`UnicodeError` has attributes that describe the encoding or decoding
+   error.  For example, ``err.object[err.start:err.end]`` gives the particular
+   invalid input that the codec failed on.
+
+   .. attribute:: encoding
+
+       The name of the encoding that raised the error.
+
+   .. attribute:: reason
+
+       A string describing the specific codec error.
+
+   .. attribute:: object
+
+       The object the codec was attempting to encode or decode.
+
+   .. attribute:: start
+
+       The first index of invalid data in :attr:`object`.
+
+   .. attribute:: end
+
+       The index after the last invalid data in :attr:`object`.
+
 
 .. exception:: UnicodeEncodeError
 

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list