Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

gh-99991: improve docs on str.encode and bytes.decode#100198

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
JelleZijlstra merged 6 commits intopython:mainfrombizzyvinci:str-docs
Dec 21, 2022
Merged
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 33 additions & 27 deletionsDoc/library/stdtypes.rst
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -1624,25 +1624,28 @@ expression support in the :mod:`re` module).

.. method:: str.encode(encoding="utf-8", errors="strict")

Return an encoded version of the string as a bytes object. Default encoding
is ``'utf-8'``. *errors* may be given to set a different error handling scheme.
The default for *errors* is ``'strict'``, meaning that encoding errors raise
a :exc:`UnicodeError`. Other possible
values are ``'ignore'``, ``'replace'``, ``'xmlcharrefreplace'``,
``'backslashreplace'`` and any other name registered via
:func:`codecs.register_error`, see section :ref:`error-handlers`. For a
list of possible encodings, see section :ref:`standard-encodings`.

By default, the *errors* argument is not checked for best performances, but
only used at the first encoding error. Enable the :ref:`Python Development
Mode <devmode>`, or use a :ref:`debug build <debug-build>` to check
*errors*.
Return the string encoded to :class:`bytes`.

*encoding* defaults to ``'utf-8'``;
see :ref:`standard-encodings` for possible values.

*errors* controls how encoding errors are handled.
If ``'strict'`` (the default), a :exc:`UnicodeError` exception is raised.
Other possible values are ``'ignore'``,
``'replace'``, ``'xmlcharrefreplace'``, ``'backslashreplace'`` and any
other name registered via :func:`codecs.register_error`.
See :ref:`error-handlers` for details.

For performance reasons, the value of *errors* is not checked for validity
unless an encoding error actually occurs,
:ref:`devmode` is enabled
or a :ref:`debug build <debug-build>` is used.

.. versionchanged:: 3.1
Supportfor keyword arguments added.
Added supportfor keyword arguments.

.. versionchanged:: 3.9
The *errors* is now checked indevelopment mode and
Thevalue of the*errors*argumentis now checked in:ref:`devmode` and
in :ref:`debug mode <debug-build>`.


Expand DownExpand Up@@ -2759,29 +2762,32 @@ arbitrary binary data.
.. method:: bytes.decode(encoding="utf-8", errors="strict")
bytearray.decode(encoding="utf-8", errors="strict")

Return a string decoded from the given bytes. Default encoding is
``'utf-8'``. *errors* may be given to set a different
error handling scheme. The default for *errors* is ``'strict'``, meaning
that encoding errors raise a :exc:`UnicodeError`. Other possible values are
``'ignore'``, ``'replace'`` and any other name registered via
:func:`codecs.register_error`, see section :ref:`error-handlers`. For a
list of possible encodings, see section :ref:`standard-encodings`.
Return the bytes decoded to a :class:`str`.

*encoding* defaults to ``'utf-8'``;
see :ref:`standard-encodings` for possible values.

*errors* controls how decoding errors are handled.
If ``'strict'`` (the default), a :exc:`UnicodeError` exception is raised.
Other possible values are ``'ignore'``, ``'replace'``,
and any other name registered via :func:`codecs.register_error`.
See :ref:`error-handlers` for details.

By default, the *errors*argumentis not checked forbest performances, but
only used at the firstdecoding error. Enable the :ref:`Python Development
Mode <devmode>`, or usea :ref:`debug build <debug-build>`to check *errors*.
For performance reasons, thevalue of*errors* is not checked forvalidity
unless adecoding error actually occurs,
:ref:`devmode` is enabled ora :ref:`debug build <debug-build>`is used.

.. note::

Passing the *encoding* argument to :class:`str` allows decoding any
:term:`bytes-like object` directly, without needing to make a temporary
bytes or bytearray object.
:class:`!bytes` or:class:`!bytearray` object.

.. versionchanged:: 3.1
Added support for keyword arguments.

.. versionchanged:: 3.9
The *errors* is now checked indevelopment mode and
Thevalue of the*errors*argumentis now checked in:ref:`devmode` and
in :ref:`debug mode <debug-build>`.


Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp