Reputation: 1655
The documentation doesn't seem to describe what it does. https://docs.python.org/3/library/stdtypes.html#bytes
I'm assuming its a typical pattern used in other functions (e.g. bytesarray) as well but I can't figure out what it does and not sure what to google for.
Upvotes: 0
Views: 775
Reputation: 7850
The description of bytes()
begins with:
Firstly, the syntax for bytes literals is largely the same as that for string literals
Looking at str()
:
If at least one of encoding or errors is given, object should be a bytes-like object (e.g.
bytes
orbytearray
). In this case, if object is abytes
(orbytearray
) object, thenstr(bytes, encoding, errors)
is equivalent tobytes.decode(encoding, errors)
.
bytes.decode()
says:
errors may be given to set a different error handling scheme. The default for errors is
'strict'
, meaning that encoding errors raise aUnicodeError
. Other possible values are'ignore'
,'replace'
and any other name registered viacodecs.register_error()
, see section Error Handlers.
So the purpose of errors
is to define how to handle encoding errors in the data. The aforementioned Error Handlers section contains more in-depth information.
Upvotes: 3