Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 4c8756c

Browse files
authored
backslashreplace is encode-only in Python 2
1 parent 00bab50 commit 4c8756c

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

programming_languages.rst

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -348,9 +348,9 @@ Python provides also many :ref:`error handlers <errors>` used to specify how to
348348
* ``replace``: replace undecodable bytes by � (U+FFFD) and unencodable
349349
characters by ``?`` (U+003F)
350350
* ``ignore``: ignore undecodable bytes and unencodable characters
351-
* ``backslashreplace`` (only to decode): replace undecodable bytes by ``\xHH``
351+
* ``backslashreplace`` (only encode): replace unencodable bytes by ``\xHH``
352352

353-
Python 3 has two more error handlers:
353+
Python 3 has three more error handlers:
354354

355355
* ``surrogateescape``: replace undecodable bytes (non-ASCII: ``0x80``\ —\
356356
``0xFF``) by :ref:`surrogate characters <surrogates>` (in U+DC80—U+DCFF) on
@@ -360,7 +360,8 @@ Python 3 has two more error handlers:
360360
* ``surrogatepass``, specific to ``UTF-8`` codec: allow encoding/decoding
361361
surrogate characters in :ref:`UTF-8`. It is required because UTF-8 decoder of
362362
Python 3 rejects surrogate characters by default.
363-
363+
* ``backslashreplace`` (for decode): replace undecodable bytes by ``\xHH``
364+
364365
Decoding examples in Python 3:
365366

366367
* ``b'abc\xff'.decode('ASCII')`` uses the ``strict`` error handler and raises

0 commit comments

Comments
 (0)