id stringlengths 36 36 | text stringlengths 6 11.2k | source_file stringclasses 558
values | section_title stringlengths 1 181 |
|---|---|---|---|
0b5525fc-2da7-4918-973a-2c7de23aa12e | This directory contains the reStructuredText (reST) sources to the Python
documentation. You don't need to build them yourself, `prebuilt versions are
available <https://docs.python.org/dev/download.html>`_.
Documentation on authoring Python documentation, including information about
both style and markup, is availab... | README.rst | Python Documentation README |
fba91c62-3a7b-4ef5-9555-ccd2e74f5fd9 | The documentation is built with several tools which are not included in this
tree but are maintained separately and are available from
`PyPI <https://pypi.org/>`_.
* `Sphinx <https://pypi.org/project/Sphinx/>`_
* `blurb <https://pypi.org/project/blurb/>`_
* `python-docs-theme <https://pypi.org/project/python-docs-them... | README.rst | Building the docs |
dd0ae1ce-cc10-4a76-98e1-797a745dfbfe | To get started on Unix, you can create a virtual environment and build documentation with the commands:: make venv make html The virtual environment in the ``venv`` directory will contain all the tools necessary to build the documentation downloaded and installed from PyPI. If you'd like to create the virtual environme... | README.rst | Using make |
da7266d2-2cec-4f83-bf0a-367ec8f7cab9 | as well as a plain-text (.txt) file. * "changes", which builds an overview over all versionadded/versionchanged/ deprecated items in the current version. This is meant as a help for the writer of the "What's New" document. * "coverage", which builds a coverage overview for standard library modules and C API. * "pydoc-t... | README.rst | Using make |
984e8ce2-5207-490e-b6be-e6851ef36ece | First, install the tool dependencies from PyPI.
Then, from the ``Doc`` directory, run ::
sphinx-build -b<builder> . build/<builder>
where ``<builder>`` is one of html, text, latex, or htmlhelp (for explanations
see the make targets above). | README.rst | Without make |
280cd164-f6dd-4254-b5ab-75508f7769c8 | You can define the ``outdated`` variable in ``html_context`` to show a
red banner on each page redirecting to the "latest" version.
The link points to the same page on ``/3/``, sadly for the moment the
language is lost during the process. | README.rst | Deprecation header |
bbd2bd7e-46d9-4fc1-9a16-dd0cd9817f96 | Bugs in the content should be reported to the
`Python bug tracker <https://github.com/python/cpython/issues>`_.
Bugs in the toolset should be reported to the tools themselves.
To help with the documentation, or report any problems, please leave a message
on `discuss.python.org <https://discuss.python.org/c/documentat... | README.rst | Contributing |
a5d714ec-e0ec-4a82-8cab-93886c29d83f | ======================== | about.rst | Introduction |
07238759-db7d-4122-b6fc-c92fbe1fadff | Python's documentation is generated from `reStructuredText`_ sources
using `Sphinx`_, a documentation generator originally created for Python
and now maintained as an independent project.
.. _reStructuredText: https://docutils.sourceforge.io/rst.html
.. _Sphinx: https://www.sphinx-doc.org/
.. In the online version of... | about.rst | About this documentation |
7359723d-06fd-471d-aed6-621ab09abcf8 | Many people have contributed to the Python language, the Python standard
library, and the Python documentation. See the `CPython
GitHub repository <https://github.com/python/cpython/graphs/contributors>`__
for a partial list of contributors.
It is only with the input and contributions of the Python community
that Pyt... | about.rst | Contributors to the Python documentation |
fadc5b02-c05b-4f4e-a246-6b0653d82e02 | .. _reporting-bugs:
***************** | bugs.rst | Introduction |
0aa61d1d-9823-4fb7-a6b7-911c0be099ed | Python is a mature programming language which has established a reputation for
stability. In order to maintain this reputation, the developers would like to
know of any deficiencies you find in Python.
It can be sometimes faster to fix bugs yourself and contribute patches to
Python as it streamlines the process and i... | bugs.rst | Dealing with Bugs |
608a85a4-6ca3-4f35-a55e-3340b2bf8e4e | If you find a bug in this documentation or would like to propose an improvement,
please submit a bug report on the :ref:`issue tracker <using-the-tracker>`. If you
have a suggestion on how to fix it, include that as well.
.. only:: translation
If the bug or suggested improvement concerns the translation of this
... | bugs.rst | Documentation bugs |
07e37ae3-dcd2-4fca-8545-c1bcda1dda95 | Issue reports for Python itself should be submitted via the GitHub issues
tracker (https://github.com/python/cpython/issues).
The GitHub issues tracker offers a web form which allows pertinent information
to be entered and submitted to the developers.
The first step in filing a report is to determine whether the probl... | bugs.rst | Using the Python issue tracker |
60d30d7c-52b7-4dfd-8567-f384f3a7dc5c | Beyond just reporting bugs that you find, you are also welcome to submit
patches to fix them. You can find more information on how to get started
patching Python in the `Python Developer's Guide`_. If you have questions,
the `core-mentorship mailing list`_ is a friendly place to get answers to
any and all questions p... | bugs.rst | Getting started contributing to Python yourself |
8a33cda8-e5ee-4132-b29b-cf12e1b8dd1f | .. highlight:: c
.. _abstract:
********************** | c-api/abstract.rst | Introduction |
b116da95-f40e-45b3-b168-c7fee1777c2e | The functions in this chapter interact with Python objects regardless of their
type, or with wide classes of object types (e.g. all numerical types, or all
sequence types). When used on object types for which they do not apply, they
will raise a Python exception.
It is not possible to use these functions on objects t... | c-api/abstract.rst | Abstract Objects Layer |
a8f81bb9-92a4-47dc-9d4e-3a997cae4fc8 | .. highlight:: c
.. _allocating-objects: | c-api/allocation.rst | Introduction |
84add54a-d145-49a5-a45b-c46250aaca93 | .. c:function:: PyObject* _PyObject_New(PyTypeObject *type) .. c:function:: PyVarObject* _PyObject_NewVar(PyTypeObject *type, Py_ssize_t size) .. c:function:: PyObject* PyObject_Init(PyObject *op, PyTypeObject *type) Initialize a newly allocated object *op* with its type and initial reference. Returns the initialized o... | c-api/allocation.rst | Allocating objects on the heap |
5ac13fef-ca60-48b8-8562-43b6bfa672d6 | c:macro:: PyObject_NewVar(TYPE, typeobj, size) Like :c:macro:`PyObject_New` except: * It allocates enough memory for the *TYPE* structure plus *size* (``Py_ssize_t``) fields of the size given by the :c:member:`~PyTypeObject.tp_itemsize` field of *typeobj*. * The memory is initialized like :c:func:`PyObject_InitVar`. Th... | c-api/allocation.rst | Allocating objects on the heap |
0078cd8e-1ff1-45e7-8863-fbf06173a216 | .. soft-deprecated:: 3.15
These are aliases to existing functions and macros.
They exist solely for backwards compatibility.
.. list-table::
:widths: auto
:header-rows: 1
* * Soft-deprecated alias
* Function
* * .. c:macro:: PyObject_NEW(type, typeobj)
* :c:macro:`PyObject_New`
* * .. c:mac... | c-api/allocation.rst | Soft-deprecated aliases |
1d903892-2ee4-4cae-aec4-37e707f10b8f | .. highlight:: c
.. _apiabiversion:
*********************** | c-api/apiabiversion.rst | Introduction |
20d7e977-8139-4025-95b9-cb866fb6c539 | CPython exposes its version number in the following macros.
Note that these correspond to the version code is **built** with.
See :c:var:`Py_Version` for the version used at **run time**.
See :ref:`stable` for a discussion of API and ABI stability across versions.
.. c:macro:: PY_MAJOR_VERSION
The ``3`` in ``3.4.... | c-api/apiabiversion.rst | Build-time version constants |
297cd7ef-b7fc-41c9-9e89-2bc8a0c07b84 | .. c:var:: const unsigned long Py_Version
The Python runtime version number encoded in a single constant integer.
See :c:func:`Py_PACK_FULL_VERSION` for the encoding details.
This contains the Python version used at run time.
Use this for numeric comparisons, for example, ``if (Py_Version >= ...)``.
.... | c-api/apiabiversion.rst | Run-time version |
d0061fce-53ec-46d3-94b9-244a973297fb | .. c:function:: uint32_t Py_PACK_FULL_VERSION(int major, int minor, int micro, int release_level, int release_serial)
Return the given version, encoded as a single 32-bit integer with
the following structure:
+------------------+-------+----------------+-----------+--------------------------+
| ... | c-api/apiabiversion.rst | Bit-packing macros |
583e589b-1368-40b9-965a-05b5ac9adee4 | .. highlight:: c
.. _arg-parsing: | c-api/arg.rst | Introduction |
99b40cc9-a1d0-40b6-8cb2-4f3d8e52cea0 | These functions are useful when creating your own extension functions and
methods. Additional information and examples are available in
:ref:`extending-index`.
The first three of these functions described, :c:func:`PyArg_ParseTuple`,
:c:func:`PyArg_ParseTupleAndKeywords`, and :c:func:`PyArg_Parse`, all use *format
st... | c-api/arg.rst | Parsing arguments and building values |
3ac74b43-4e31-4dcf-960e-ed12bc65c15e | A format string consists of zero or more "format units." A format unit
describes one Python object; it is usually a single character or a parenthesized
sequence of format units. With a few exceptions, a format unit that is not a
parenthesized sequence normally corresponds to a single address argument to
these functio... | c-api/arg.rst | Parsing arguments |
55d36266-324e-4df1-a2b9-41f8289406c3 | .. note:: On Python 3.12 and older, the macro :c:macro:`!PY_SSIZE_T_CLEAN` must be defined before including :file:`Python.h` to use all ``#`` variants of formats (``s#``, ``y#``, etc.) explained below. This is not necessary on Python 3.13 and later. These formats allow accessing an object as a contiguous chunk of memor... | c-api/arg.rst | Strings and buffers |
6f133813-9a60-4002-86ad-9cf1b3ba3631 | does, a :exc:`ValueError` exception is raised. Unicode objects are converted to C strings using ``'utf-8'`` encoding. If this conversion fails, a :exc:`UnicodeError` is raised. .. note:: This format does not accept :term:`bytes-like objects <bytes-like object>`. If you want to accept filesystem paths and convert them t... | c-api/arg.rst | Strings and buffers |
21e9f07b-0621-40c8-921d-62c033e2d2f2 | objects. **This is the recommended way to accept binary data.** ``y#`` (read-only :term:`bytes-like object`) [const char \*, :c:type:`Py_ssize_t`] This variant on ``s#`` doesn't accept Unicode objects, only bytes-like objects. ``S`` (:class:`bytes`) [PyBytesObject \*] Requires that the Python object is a :class:`bytes`... | c-api/arg.rst | Strings and buffers |
d648008d-e2bb-43f8-9b3f-05591b1c3725 | \*encoding, char \*\*buffer] Same as ``es`` except that byte string objects are passed through without recoding them. Instead, the implementation assumes that the byte string object uses the encoding passed in as parameter. ``es#`` (:class:`str`) [const char \*encoding, char \*\*buffer, :c:type:`Py_ssize_t` \*buffer_le... | c-api/arg.rst | Strings and buffers |
189e0507-37ec-4de7-83fe-127148cb005f | These formats allow representing Python numbers or single characters as C numbers. Formats that require :class:`int`, :class:`float` or :class:`complex` can also use the corresponding special methods :meth:`~object.__index__`, :meth:`~object.__float__` or :meth:`~object.__complex__` to convert the Python object to the ... | c-api/arg.rst | Numbers |
7a2b1350-8db4-4c2b-bd3c-a5024c08a091 | [float] Convert a Python floating-point number to a C :c:expr:`float`. ``d`` (:class:`float`) [double] Convert a Python floating-point number to a C :c:expr:`double`. ``D`` (:class:`complex`) [Py_complex] Convert a Python complex number to a C :c:type:`Py_complex` structure. .. deprecated:: 3.15 For unsigned integer fo... | c-api/arg.rst | Numbers |
0bb61d7d-21dd-4830-9ebe-847ebc093108 | ``O`` (object) [PyObject \*] Store a Python object (without any conversion) in a C object pointer. The C program thus receives the actual object that was passed. A new :term:`strong reference` to the object is not created (i.e. its reference count is not increased). The pointer stored is not ``NULL``. ``O!`` (object) [... | c-api/arg.rst | Other objects |
324edb71-0e04-463a-b59e-b5a17e47b527 | about how Python tests values for truth. .. versionadded:: 3.3 ``(items)`` (sequence) [*matching-items*] The object must be a Python sequence (except :class:`str`, :class:`bytes` or :class:`bytearray`) whose length is the number of format units in *items*. The C arguments must correspond to the individual format units ... | c-api/arg.rst | Other objects |
1cd733a1-8744-4458-a8ac-dc11a373996d | that any Python object references which are provided to the caller are *borrowed* references; do not release them (i.e. do not decrement their reference count)! Additional arguments passed to these functions must be addresses of variables whose type is determined by the format string; these are used to store values fro... | c-api/arg.rst | Other objects |
2351a631-1f2e-4225-966c-761f1c0bdda0 | .. c:function:: int PyArg_ParseTuple(PyObject *args, const char *format, ...) Parse the parameters of a function that takes only positional parameters into local variables. Returns true on success; on failure, it returns false and raises the appropriate exception. .. c:function:: int PyArg_VaParse(PyObject *args, const... | c-api/arg.rst | API Functions |
579f09f2-ecda-46ab-b313-fe1b2a15f26a | const char *format, ...) Parse the parameters of a function that takes only array parameters into local variables (that is, a function using the :c:macro:`METH_FASTCALL` calling convention). Returns true on success; on failure, it returns false and raises the appropriate exception. .. versionadded:: 3.15 .. c:function:... | c-api/arg.rst | API Functions |
0df2c30a-9d5e-43d4-977f-f279b3230702 | is entirely equivalent to this call to :c:func:`PyArg_ParseTuple`:: PyArg_ParseTuple(args, "O|O:ref", &object, &callback) .. c:macro:: PY_CXX_CONST The value to be inserted, if any, before :c:expr:`char * const *` in the *keywords* parameter declaration of :c:func:`PyArg_ParseTupleAndKeywords` and :c:func:`PyArg_VaPars... | c-api/arg.rst | API Functions |
edea4da5-063f-4a70-a9f0-d2bea00d32be | .. c:function:: PyObject* Py_BuildValue(const char *format, ...) Create a new value based on a format string similar to those accepted by the ``PyArg_Parse*`` family of functions and a sequence of values. Returns the value or ``NULL`` in the case of an error; an exception will be raised if ``NULL`` is returned. :c:func... | c-api/arg.rst | Building values |
a549000d-3f99-4835-92d7-97bf8fea310b | returned. ``y#`` (:class:`bytes`) [const char \*, :c:type:`Py_ssize_t`] This converts a C string and its lengths to a Python object. If the C string pointer is ``NULL``, ``None`` is returned. ``z`` (:class:`str` or ``None``) [const char \*] Same as ``s``. ``z#`` (:class:`str` or ``None``) [const char \*, :c:type:`Py_ss... | c-api/arg.rst | Building values |
2304ca87-7b8e-415f-8bd6-c86a043a0b2c | ``(x) ? 1 : 0`` or ``!!x``. .. versionadded:: 3.14 ``c`` (:class:`bytes` of length 1) [char] Convert a C :c:expr:`int` representing a byte to a Python :class:`bytes` object of length 1. ``C`` (:class:`str` of length 1) [int] Convert a C :c:expr:`int` representing a character to Python :class:`str` object of length 1. `... | c-api/arg.rst | Building values |
73f233e9-da86-486e-a317-6817f8003a46 | .. highlight:: c
.. _boolobjects: | c-api/bool.rst | Introduction |
a2b6001f-61fc-45c7-b936-d1f8dff23979 | Booleans in Python are implemented as a subclass of integers. There are only
two booleans, :c:data:`Py_False` and :c:data:`Py_True`. As such, the normal
creation and deletion functions don't apply to booleans. The following macros
are available, however.
.. c:var:: PyTypeObject PyBool_Type
This instance of :c:... | c-api/bool.rst | Boolean Objects |
8ee18041-d82b-4d2b-92ba-9a3290b8916c | .. highlight:: c
.. index::
single: buffer protocol
single: buffer interface; (see buffer protocol)
single: buffer object; (see buffer protocol)
.. _bufferobjects: | c-api/buffer.rst | Introduction |
b50b7b63-f374-464f-ae76-bd5d678f3a45 | Certain objects available in Python wrap access to an underlying memory
array or *buffer*. Such objects include the built-in :class:`bytes` and
:class:`bytearray`, and some extension types like :class:`array.array`.
Third-party libraries may define their own types for special purposes, such
as image processing or nume... | c-api/buffer.rst | Buffer Protocol |
e1d5ec5d-7de3-475d-b78d-03152b751910 | Buffer structures (or simply "buffers") are useful as a way to expose the binary data from another object to the Python programmer. They can also be used as a zero-copy slicing mechanism. Using their ability to reference a block of memory, it is possible to expose any data to the Python programmer quite easily. The mem... | c-api/buffer.rst | Buffer structure |
aca46ced-0c0e-441a-adcc-b27ceb410c3f | if the buffer has been obtained by a request that guarantees contiguity. In most cases such a request will be :c:macro:`PyBUF_SIMPLE` or :c:macro:`PyBUF_WRITABLE`. .. c:member:: int readonly An indicator of whether the buffer is read-only. This field is controlled by the :c:macro:`PyBUF_WRITABLE` flag. .. c:member:: Py... | c-api/buffer.rst | Buffer structure |
68be3c7c-7a87-44e4-943b-c9af928207fe | strides array is read-only for the consumer. .. c:member:: Py_ssize_t *suboffsets An array of :c:type:`Py_ssize_t` of length :c:member:`~Py_buffer.ndim`. If ``suboffsets[n] >= 0``, the values stored along the nth dimension are pointers and the suboffset value dictates how many bytes to add to each pointer after de-refe... | c-api/buffer.rst | Buffer structure |
23f554ba-89b4-4940-aaa9-e552b3db9aee | Buffers are usually obtained by sending a buffer request to an exporting
object via :c:func:`PyObject_GetBuffer`. Since the complexity of the logical
structure of the memory can vary drastically, the consumer uses the *flags*
argument to specify the exact buffer type it can handle.
All :c:type:`Py_buffer` fields are u... | c-api/buffer.rst | Buffer request types |
e699ef9f-b35b-40c4-820a-3de6d9d92b12 | The following fields are not influenced by *flags* and must always be filled in
with the correct values: :c:member:`~Py_buffer.obj`, :c:member:`~Py_buffer.buf`,
:c:member:`~Py_buffer.len`, :c:member:`~Py_buffer.itemsize`, :c:member:`~Py_buffer.ndim`. | c-api/buffer.rst | request-independent fields |
69789972-2e57-4234-b179-4ff0c361246c | .. c:macro:: PyBUF_WRITABLE
Controls the :c:member:`~Py_buffer.readonly` field. If set, the exporter
MUST provide a writable buffer or else report failure. Otherwise, the
exporter MAY provide either a read-only or writable buffer, but the choice
MUST be consistent for all consumers. For example... | c-api/buffer.rst | readonly, format |
98e9b257-a1c1-437e-b664-fbc5acebf290 | The flags that control the logical structure of the memory are listed
in decreasing order of complexity. Note that each flag contains all bits
of the flags below it.
.. tabularcolumns:: |p{0.35\linewidth}|l|l|l|
+-----------------------------+-------+---------+------------+
| Request | shape | str... | c-api/buffer.rst | shape, strides, suboffsets |
94beef3d-1764-414e-89c2-b4cefce55180 | C or Fortran :term:`contiguity <contiguous>` can be explicitly requested,
with and without stride information. Without stride information, the buffer
must be C-contiguous.
.. tabularcolumns:: |p{0.35\linewidth}|l|l|l|l|
+-----------------------------------+-------+---------+------------+--------+
| Request ... | c-api/buffer.rst | contiguity requests |
0c05e86f-b5ba-4548-9ea7-033ddf8e4b8b | All possible requests are fully defined by some combination of the flags in
the previous section. For convenience, the buffer protocol provides frequently
used combinations as single flags.
In the following table *U* stands for undefined contiguity. The consumer would
have to call :c:func:`PyBuffer_IsContiguous` to de... | c-api/buffer.rst | compound requests |
ae200053-80c9-408c-b859-d18defa86ca7 | The logical structure of NumPy-style arrays is defined by :c:member:`~Py_buffer.itemsize`,
:c:member:`~Py_buffer.ndim`, :c:member:`~Py_buffer.shape` and :c:member:`~Py_buffer.strides`.
If ``ndim == 0``, the memory location pointed to by :c:member:`~Py_buffer.buf` is
interpreted as a scalar of size :c:member:`~Py_buffe... | c-api/buffer.rst | NumPy-style: shape and strides |
cf77cca7-4137-4c18-8c55-09b15097ba1d | In addition to the regular items, PIL-style arrays can contain pointers
that must be followed in order to get to the next element in a dimension.
For example, the regular three-dimensional C-array ``char v[2][2][3]`` can
also be viewed as an array of 2 pointers to 2 two-dimensional arrays:
``char (*v[2])[2][3]``. In su... | c-api/buffer.rst | PIL-style: shape, strides and suboffsets |
56380a1a-73bc-4407-af52-6b17087ba143 | .. c:function:: int PyObject_CheckBuffer(PyObject *obj) Return ``1`` if *obj* supports the buffer interface otherwise ``0``. When ``1`` is returned, it doesn't guarantee that :c:func:`PyObject_GetBuffer` will succeed. This function always succeeds. .. c:function:: int PyObject_GetBuffer(PyObject *exporter, Py_buffer *v... | c-api/buffer.rst | Buffer-related functions |
1807c435-e6cd-4942-bb75-9a720d160685 | c:function:: int PyBuffer_ToContiguous(void *buf, const Py_buffer *src, Py_ssize_t len, char order) Copy *len* bytes from *src* to its contiguous representation in *buf*. *order* can be ``'C'`` or ``'F'`` or ``'A'`` (for C-style or Fortran-style ordering or either one). ``0`` is returned on success, ``-1`` on error. Th... | c-api/buffer.rst | Buffer-related functions |
7cf6ce07-797a-4dea-b672-24319c3f827f | .. highlight:: c
.. _bytearrayobjects: | c-api/bytearray.rst | Introduction |
c0d02c2d-5548-403a-809d-d98f4303e8cb | .. index:: pair: object; bytearray
.. c:type:: PyByteArrayObject
This subtype of :c:type:`PyObject` represents a Python bytearray object.
.. c:var:: PyTypeObject PyByteArray_Type
This instance of :c:type:`PyTypeObject` represents the Python bytearray type;
it is the same object as :class:`bytearray` in t... | c-api/bytearray.rst | Byte Array Objects |
03f52a43-704f-4a3b-b15c-48dac68eeb61 | .. c:function:: int PyByteArray_Check(PyObject *o)
Return true if the object *o* is a bytearray object or an instance of a
subtype of the bytearray type. This function always succeeds.
.. c:function:: int PyByteArray_CheckExact(PyObject *o)
Return true if the object *o* is a bytearray object, but not an i... | c-api/bytearray.rst | Type check macros |
5b61c37c-35db-43a9-9389-ea245625dd23 | .. c:function:: PyObject* PyByteArray_FromObject(PyObject *o)
Return a new bytearray object from any object, *o*, that implements the
:ref:`buffer protocol <bufferobjects>`.
On failure, return ``NULL`` with an exception set.
.. note::
If the object implements the buffer protocol, then the buffer
... | c-api/bytearray.rst | Direct API functions |
78d428b5-036f-47a9-aa36-a0e1ebdec819 | These macros trade safety for speed and they don't check pointers.
.. c:function:: char* PyByteArray_AS_STRING(PyObject *bytearray)
Similar to :c:func:`PyByteArray_AsString`, but without error checking.
.. note::
It is not thread-safe to mutate the bytearray object while using the returned char array.
... | c-api/bytearray.rst | Macros |
c7d3b35b-f1ef-4dca-b102-965e47cb84b9 | .. highlight:: c
.. _bytesobjects: | c-api/bytes.rst | Introduction |
d379c2cf-2f7d-4951-8431-54360a5af86b | These functions raise :exc:`TypeError` when expecting a bytes parameter and called with a non-bytes parameter. .. index:: pair: object; bytes .. c:type:: PyBytesObject This subtype of :c:type:`PyObject` represents a Python bytes object. .. c:var:: PyTypeObject PyBytes_Type This instance of :c:type:`PyTypeObject` repres... | c-api/bytes.rst | Bytes Objects |
9fab4758-9878-4eff-b2fb-9ea1775be21a | [1]_ | +-------------------+---------------+--------------------------------+ | ``%u`` | unsigned int | Equivalent to | | | | ``printf("%u")``. [1]_ | +-------------------+---------------+--------------------------------+ | ``%ld`` | long | Equivalent to | | | | ``printf("%ld")``. [1]_ | +-------------------+----------... | c-api/bytes.rst | Bytes Objects |
3ce385b2-b297-4d46-bfc3-78723d81b63f | 1`` bytes. The last byte in the buffer is always null, regardless of whether there are any other null bytes. The data must not be modified in any way, unless the object was just created using ``PyBytes_FromStringAndSize(NULL, size)``. It must not be deallocated. If *o* is not a bytes object at all, :c:func:`PyBytes_AsS... | c-api/bytes.rst | Bytes Objects |
1f7cb2b0-2612-448c-a1e1-a300e08bfa2a | object is being created. .. c:function:: PyObject* PyBytes_Join(PyObject *sep, PyObject *iterable) Similar to ``sep.join(iterable)`` in Python. *sep* must be Python :class:`bytes` object. (Note that :c:func:`PyUnicode_Join` accepts ``NULL`` separator and treats it as a space, whereas :c:func:`PyBytes_Join` doesn't acce... | c-api/bytes.rst | Bytes Objects |
1c7cc5cf-d6c7-4c58-bd62-c06bb9e2be8c | size of *s*. *errors* must be one of ``"strict"``, ``"replace"``, or ``"ignore"``. If *errors* is ``NULL``, then ``"strict"`` is used by default. On success, this function returns a :term:`strong reference` to a Python :class:`bytes` object containing the unescaped string. On failure, this function returns ``NULL`` wit... | c-api/bytes.rst | Bytes Objects |
537bb670-42f7-44e9-8aa4-9b2b392122d5 | The :c:type:`PyBytesWriter` API can be used to create a Python :class:`bytes`
object.
.. versionadded:: 3.15
.. c:type:: PyBytesWriter
A bytes writer instance.
The API is **not thread safe**: a writer should only be used by a single
thread at the same time.
The instance must be destroyed by :c:func:`Py... | c-api/bytes.rst | PyBytesWriter |
b3023e5e-0512-405d-8cd1-846e1ae597a5 | .. c:function:: PyBytesWriter* PyBytesWriter_Create(Py_ssize_t size)
Create a :c:type:`PyBytesWriter` to write *size* bytes.
If *size* is greater than zero, allocate *size* bytes, and set the
writer size to *size*. The caller is responsible to write *size*
bytes using :c:func:`PyBytesWriter_GetData`.
T... | c-api/bytes.rst | Create, Finish, Discard |
82500307-cdfc-430f-80d8-d37e60b533bd | .. c:function:: int PyBytesWriter_WriteBytes(PyBytesWriter *writer, const void *bytes, Py_ssize_t size)
Grow the *writer* internal buffer by *size* bytes,
write *size* bytes of *bytes* at the *writer* end,
and add *size* to the *writer* size.
If *size* is equal to ``-1``, call ``strlen(bytes)`` to get the... | c-api/bytes.rst | High-level API |
8ae8eee0-eda3-44d5-bc62-4743b87c0996 | .. c:function:: Py_ssize_t PyBytesWriter_GetSize(PyBytesWriter *writer)
Get the writer size.
The function does not invalidate pointers returned by
:c:func:`PyBytesWriter_GetData`.
The function cannot fail.
.. c:function:: void* PyBytesWriter_GetData(PyBytesWriter *writer)
Get the writer data: start ... | c-api/bytes.rst | Getters |
a3477342-a78a-4e59-afdf-945b78a3dc85 | .. c:function:: int PyBytesWriter_Resize(PyBytesWriter *writer, Py_ssize_t size)
Resize the writer to *size* bytes. It can be used to enlarge or to
shrink the writer.
This function typically overallocates to achieve amortized performance when
resizing multiple times.
Newly allocated bytes are left unin... | c-api/bytes.rst | Low-level API |
6711aace-d918-4b1c-9624-be234079b846 | .. highlight:: c
.. _call: | c-api/call.rst | Introduction |
5bdf5d12-d20d-4fd0-a0ae-7a128952d655 | CPython supports two different calling protocols:
*tp_call* and vectorcall. | c-api/call.rst | Call Protocol |
b48e7a38-408e-47a4-bf24-6132affd9cf0 | Instances of classes that set :c:member:`~PyTypeObject.tp_call` are callable.
The signature of the slot is::
PyObject *tp_call(PyObject *callable, PyObject *args, PyObject *kwargs);
A call is made using a tuple for the positional arguments
and a dict for the keyword arguments, similarly to
``callable(*args, **kwa... | c-api/call.rst | The *tp_call* Protocol |
5b79ed4d-a513-44d1-a5b1-36a1b2828d8a | .. versionadded:: 3.9 The vectorcall protocol was introduced in :pep:`590` as an additional protocol for making calls more efficient. As rule of thumb, CPython will prefer the vectorcall for internal calls if the callable supports it. However, this is not a hard rule. Additionally, some third-party extensions use *tp_c... | c-api/call.rst | The Vectorcall Protocol |
149e12ff-affe-4f75-b9f3-037c35f640b3 | *NULL*. .. c:macro:: PY_VECTORCALL_ARGUMENTS_OFFSET If this flag is set in a vectorcall *nargsf* argument, the callee is allowed to temporarily change ``args[-1]``. In other words, *args* points to argument 1 (not 0) in the allocated vector. The callee must restore the value of ``args[-1]`` before returning. For :c:fun... | c-api/call.rst | The Vectorcall Protocol |
94f99edf-2b03-42b5-ad4e-79c87ff37125 | When using *tp_call*, callees do not need to worry about
:ref:`recursion <recursion>`: CPython uses
:c:func:`Py_EnterRecursiveCall` and :c:func:`Py_LeaveRecursiveCall`
for calls made using *tp_call*.
For efficiency, this is not the case for calls done using vectorcall:
the callee should use *Py_EnterRecursiveCall* and... | c-api/call.rst | Recursion Control |
0a2a0916-b214-483c-8030-313160994eef | .. c:function:: Py_ssize_t PyVectorcall_NARGS(size_t nargsf)
Given a vectorcall *nargsf* argument, return the actual number of
arguments.
Currently equivalent to::
(Py_ssize_t)(nargsf & ~PY_VECTORCALL_ARGUMENTS_OFFSET)
However, the function ``PyVectorcall_NARGS`` should be used to allow
for futu... | c-api/call.rst | Vectorcall Support API |
ae482495-9057-4a93-af8e-04def56305ac | Various functions are available for calling a Python object. Each converts its arguments to a convention supported by the called object – either *tp_call* or vectorcall. In order to do as little conversion as possible, pick one that best fits the format of data you have available. The following table summarizes the ava... | c-api/call.rst | Object Calling API |
ec514bbb-c34f-432e-9540-daba19dc42c9 | 3.9 .. c:function:: PyObject* PyObject_CallOneArg(PyObject *callable, PyObject *arg) Call a callable Python object *callable* with exactly 1 positional argument *arg* and no keyword arguments. Return the result of the call on success, or raise an exception and return *NULL* on failure. .. versionadded:: 3.9 .. c:functi... | c-api/call.rst | Object Calling API |
d3ff333b-50b3-431c-be22-7b2a2791568c | and return *NULL* on failure. This is the equivalent of the Python expression: ``callable(arg1, arg2, ...)``. .. c:function:: PyObject* PyObject_CallMethodObjArgs(PyObject *obj, PyObject *name, ...) Call a method of the Python object *obj*, where the name of the method is given as a Python string object in *name*. It i... | c-api/call.rst | Object Calling API |
223f4f72-db18-43e8-a281-94aea36b69e3 | should only be used if the caller already has a dictionary ready to use for the keyword arguments, but not a tuple for the positional arguments. .. versionadded:: 3.9 .. c:function:: PyObject* PyObject_VectorcallMethod(PyObject *name, PyObject *const *args, size_t nargsf, PyObject *kwnames) Call a method using the vect... | c-api/call.rst | Object Calling API |
6c11abe3-9292-4827-896b-a3321c977bf2 | .. c:function:: int PyCallable_Check(PyObject *o)
Determine if the object *o* is callable. Return ``1`` if the object is callable
and ``0`` otherwise. This function always succeeds. | c-api/call.rst | Call Support API |
0adbf388-1518-4093-b5ff-d09a9a8ab5d2 | .. highlight:: c
.. _capsules: | c-api/capsule.rst | Introduction |
f16977a4-91fb-4b06-86b0-4b5169854713 | .. index:: pair: object; Capsule Refer to :ref:`using-capsules` for more information on using these objects. .. versionadded:: 3.1 .. c:type:: PyCapsule This subtype of :c:type:`PyObject` represents an opaque value, useful for C extension modules which need to pass an opaque value (as a :c:expr:`void*` pointer) through... | c-api/capsule.rst | Capsules |
51db170d-be77-45c8-b4ab-772829e2308b | ``NULL``. It is legal for a capsule to have a ``NULL`` destructor. This makes a ``NULL`` return code somewhat ambiguous; use :c:func:`PyCapsule_IsValid` or :c:func:`PyErr_Occurred` to disambiguate. .. c:function:: void* PyCapsule_GetContext(PyObject *capsule) Return the current context stored in the capsule. On failure... | c-api/capsule.rst | Capsules |
b1879ac6-cb76-4951-8b88-0dff80fe2fc6 | success. Return nonzero and set an exception on failure. .. c:function:: int PyCapsule_SetName(PyObject *capsule, const char *name) Set the name inside *capsule* to *name*. If non-``NULL``, the name must outlive the capsule. If the previous *name* stored in the capsule was not ``NULL``, no attempt is made to free it. R... | c-api/capsule.rst | Capsules |
fd88c7b5-80a0-4e9d-82d7-91a00765960a | .. highlight:: c
.. _cell-objects: | c-api/cell.rst | Introduction |
4dd63ded-7c63-4909-b74a-3b03b6cbc9dd | "Cell" objects are used to implement variables referenced by multiple scopes.
For each such variable, a cell object is created to store the value; the local
variables of each stack frame that references the value contain a reference to
the cells from outer scopes which also use that variable. When the value is
accesse... | c-api/cell.rst | Cell Objects |
5a9b1a2f-74b3-44a1-b128-0bfe0960047a | .. highlight:: c
.. index:: object; code, code object
.. _codeobjects: | c-api/code.rst | Introduction |
69d46a00-8827-4bc1-a93e-07059e609abe | Code objects are a low-level detail of the CPython implementation. Each one represents a chunk of executable code that hasn't yet been bound into a function. .. c:type:: PyCodeObject The C structure of the objects used to describe code objects. The fields of this type are subject to change at any time. .. c:var:: PyTyp... | c-api/code.rst | Code Objects |
29f339d3-c8ca-49aa-b69e-e9b2589d0395 | The same caveats that apply to ``PyUnstable_Code_New`` also apply to this function. .. versionadded:: 3.8 as ``PyCode_NewWithPosOnlyArgs`` .. versionchanged:: 3.11 Added ``qualname`` and ``exceptiontable`` parameters. .. versionchanged:: 3.12 Renamed to ``PyUnstable_Code_NewWithPosOnlyArgs``. The old name is deprecated... | c-api/code.rst | Code Objects |
f8d9a9b9-25d9-4b5d-a8d4-223911ef12c2 | 3.11 .. c:function:: PyObject* PyCode_GetFreevars(PyCodeObject *co) Equivalent to the Python code ``getattr(co, 'co_freevars')``. Returns a new reference to a :c:type:`PyTupleObject` containing the names of the :term:`free (closure) variables <closure variable>`. On error, ``NULL`` is returned and an exception is raise... | c-api/code.rst | Code Objects |
ecd11c75-0236-42b5-a214-7c89eeb72e4e | should return ``0`` with the same exception still set. This means the callback may not call any other API that can set an exception unless it saves and clears the exception state first, and restores it before returning. .. versionadded:: 3.12 .. c:function:: PyObject *PyCode_Optimize(PyObject *code, PyObject *consts, P... | c-api/code.rst | Code Objects |
e08b25ea-266b-4114-a199-136bf80760da | Code objects contain a bit-field of flags, which can be retrieved as the
:attr:`~codeobject.co_flags` Python attribute (for example using
:c:func:`PyObject_GetAttrString`), and set using a *flags* argument to
:c:func:`PyUnstable_Code_New` and similar functions.
Flags whose names start with ``CO_FUTURE_`` correspond to... | c-api/code.rst | Code Object Flags |
End of preview. Expand in Data Studio
No dataset card yet
- Downloads last month
- -