Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
46 changes: 12 additions & 34 deletions Doc/library/functions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1422,38 +1422,10 @@ are always available. They are listed here in alphabetical order.

*errors* is an optional string that specifies how encoding and decoding
errors are to be handled—this cannot be used in binary mode.
A variety of standard error handlers are available
(listed under :ref:`error-handlers`), though any
error handling name that has been registered with
A variety of standard error handlers are available,
though any error handling name that has been registered with
:func:`codecs.register_error` is also valid. The standard names
include:

* ``'strict'`` to raise a :exc:`ValueError` exception if there is
an encoding error. The default value of ``None`` has the same
effect.

* ``'ignore'`` ignores errors. Note that ignoring encoding errors
can lead to data loss.

* ``'replace'`` causes a replacement marker (such as ``'?'``) to be inserted
where there is malformed data.

* ``'surrogateescape'`` will represent any incorrect bytes as low
surrogate code units ranging from U+DC80 to U+DCFF.
These surrogate code units will then be turned back into
the same bytes when the ``surrogateescape`` error handler is used
when writing data. This is useful for processing files in an
unknown encoding.

* ``'xmlcharrefreplace'`` is only supported when writing to a file.
Characters not supported by the encoding are replaced with the
appropriate XML character reference :samp:`&#{nnn};`.

* ``'backslashreplace'`` replaces malformed data by Python's backslashed
escape sequences.

* ``'namereplace'`` (also only supported when writing)
replaces unsupported characters with ``\N{...}`` escape sequences.
can be found in :ref:`error-handlers`.

.. index::
single: universal newlines; open() built-in function
Expand Down Expand Up @@ -1562,13 +1534,19 @@ are always available. They are listed here in alphabetical order.
.. versionchanged:: 3.11
The ``'U'`` mode has been removed.

.. function:: ord(c)
.. function:: ord(character, /)

Given a string representing one Unicode character, return an integer
representing the Unicode code point of that character. For example,
Return the ordinal value of a character.

If the argument is a one-character string, return the Unicode code point
of that character. For example,
``ord('a')`` returns the integer ``97`` and ``ord('€')`` (Euro sign)
returns ``8364``. This is the inverse of :func:`chr`.

If the argument is a :class:`bytes` or :class:`bytearray` object of
length 1, return its single byte value.
For example, ``ord(b'a')`` returns the integer ``97``.


.. function:: pow(base, exp, mod=None)

Expand Down
8 changes: 8 additions & 0 deletions Lib/calendar.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,14 @@ def __len__(self):
except ValueError:
standalone_month_name = month_name
standalone_month_abbr = month_abbr
else:
# Some systems that do not support '%OB' will keep it as-is (i.e.,
# we get [..., '%OB', '%OB', '%OB']), so for non-distinct names,
# we fall back to month_name/month_abbr.
if len(set(standalone_month_name)) != len(set(month_name)):
standalone_month_name = month_name
if len(set(standalone_month_abbr)) != len(set(month_abbr)):
standalone_month_abbr = month_abbr


def isleap(year):
Expand Down
12 changes: 9 additions & 3 deletions Python/bltinmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -2118,15 +2118,21 @@ builtin_oct(PyObject *module, PyObject *number)
/*[clinic input]
ord as builtin_ord

c: object
character as c: object
/

Return the Unicode code point for a one-character string.
Return the ordinal value of a character.

If the argument is a one-character string, return the Unicode code
point of that character.

If the argument is a bytes or bytearray object of length 1, return its
single byte value.
[clinic start generated code]*/

static PyObject *
builtin_ord(PyObject *module, PyObject *c)
/*[clinic end generated code: output=4fa5e87a323bae71 input=3064e5d6203ad012]*/
/*[clinic end generated code: output=4fa5e87a323bae71 input=98d38480432e1177]*/
{
long ord;
Py_ssize_t size;
Expand Down
12 changes: 9 additions & 3 deletions Python/clinic/bltinmodule.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading