Кортежні об’єкти¶
-
PyTypeObject PyTuple_Type¶
- Part of the Stable ABI.
Цей екземпляр
PyTypeObjectпредставляє тип кортежу Python; це той самий об’єкт, що йtupleна рівні Python.
-
int PyTuple_Check(PyObject *p)¶
Повертає true, якщо p є об’єктом кортежу або екземпляром підтипу типу кортежу. Ця функція завжди успішна.
-
int PyTuple_CheckExact(PyObject *p)¶
Повертає true, якщо p є об’єктом кортежу, але не екземпляром підтипу типу кортежу. Ця функція завжди успішна.
-
PyObject *PyTuple_New(Py_ssize_t len)¶
- Return value: New reference. Part of the Stable ABI.
Return a new tuple object of size len, or
NULLon failure.
-
PyObject *PyTuple_Pack(Py_ssize_t n, ...)¶
- Return value: New reference. Part of the Stable ABI.
Return a new tuple object of size n, or
NULLon failure. The tuple values are initialized to the subsequent n C arguments pointing to Python objects.PyTuple_Pack(2, a, b)is equivalent toPy_BuildValue("(OO)", a, b).
-
Py_ssize_t PyTuple_Size(PyObject *p)¶
- Part of the Stable ABI.
Take a pointer to a tuple object, and return the size of that tuple.
-
Py_ssize_t PyTuple_GET_SIZE(PyObject *p)¶
Return the size of the tuple p, which must be non-
NULLand point to a tuple; no error checking is performed.
-
PyObject *PyTuple_GetItem(PyObject *p, Py_ssize_t pos)¶
- Return value: Borrowed reference. Part of the Stable ABI.
Повертає об’єкт у позицію pos у кортежі, на який вказує p. Якщо pos є негативним або виходить за межі, поверніть
NULLі встановіть винятокIndexError.
-
PyObject *PyTuple_GET_ITEM(PyObject *p, Py_ssize_t pos)¶
- Return value: Borrowed reference.
Як
PyTuple_GetItem(), але не перевіряє його аргументи.
-
PyObject *PyTuple_GetSlice(PyObject *p, Py_ssize_t low, Py_ssize_t high)¶
- Return value: New reference. Part of the Stable ABI.
Return the slice of the tuple pointed to by p between low and high, or
NULLon failure. This is the equivalent of the Python expressionp[low:high]. Indexing from the end of the list is not supported.
-
int PyTuple_SetItem(PyObject *p, Py_ssize_t pos, PyObject *o)¶
- Part of the Stable ABI.
Вставте посилання на об’єкт o у позиції pos кортежу, на який вказує p. У разі успіху повертає
0. Якщо pos виходить за межі, поверніть-1і встановіть винятокIndexError.Примітка
Ця функція «викрадає» посилання на o та відкидає посилання на елемент, який уже міститься в кортежі в ураженій позиції.
-
void PyTuple_SET_ITEM(PyObject *p, Py_ssize_t pos, PyObject *o)¶
Подібно до
PyTuple_SetItem(), але не перевіряє помилки, і його слід використовувати лише для заповнення абсолютно нових кортежів.Примітка
This function «steals» a reference to o, and, unlike
PyTuple_SetItem(), does not discard a reference to any item that is being replaced; any reference in the tuple at position pos will be leaked.
-
int _PyTuple_Resize(PyObject **p, Py_ssize_t newsize)¶
Можна використовувати для зміни розміру кортежу. newsize буде новою довжиною кортежу. Оскільки кортежі вважаються незмінними, це слід використовувати, лише якщо є лише одне посилання на об’єкт. Не використовуйте це, якщо кортеж може бути вже відомий іншій частині коду. Кортеж завжди зростатиме або зменшуватиметься в кінці. Думайте про це як про знищення старого кортежу та створення нового, але більш ефективного. У разі успіху повертає
0. Клієнтський код ніколи не повинен вважати, що результуюче значення*pбуде таким самим, як і до виклику цієї функції. Якщо об’єкт, на який посилається*p, замінюється, оригінальний*pзнищується. У разі помилки повертає-1і встановлює*pзначенняNULLі викликаєMemoryErrorабоSystemError.
Структуруйте об’єкти послідовності¶
Об’єкти послідовності структур є еквівалентом C об’єктів namedtuple(), тобто послідовності, до елементів якої також можна отримати доступ через атрибути. Щоб створити послідовність структур, спочатку потрібно створити певний тип послідовності структур.
-
PyTypeObject *PyStructSequence_NewType(PyStructSequence_Desc *desc)¶
- Return value: New reference. Part of the Stable ABI.
Створіть новий тип послідовності структур із даних у desc, як описано нижче. Екземпляри отриманого типу можна створити за допомогою
PyStructSequence_New().
-
void PyStructSequence_InitType(PyTypeObject *type, PyStructSequence_Desc *desc)¶
Ініціалізує структурну послідовність типу type з desc на місці.
-
int PyStructSequence_InitType2(PyTypeObject *type, PyStructSequence_Desc *desc)¶
The same as
PyStructSequence_InitType, but returns0on success and-1on failure.Нове в версії 3.4.
-
type PyStructSequence_Desc¶
- Part of the Stable ABI (including all members).
Містить метаінформацію типу послідовності структур, яку потрібно створити.
-
const char *name¶
Name of the struct sequence type.
-
const char *doc¶
Pointer to docstring for the type or
NULLto omit.
-
PyStructSequence_Field *fields¶
Pointer to
NULL-terminated array with field names of the new type.
-
int n_in_sequence¶
Number of fields visible to the Python side (if used as tuple).
-
const char *name¶
-
type PyStructSequence_Field¶
- Part of the Stable ABI (including all members).
Describes a field of a struct sequence. As a struct sequence is modeled as a tuple, all fields are typed as PyObject*. The index in the
fieldsarray of thePyStructSequence_Descdetermines which field of the struct sequence is described.-
const char *name¶
Name for the field or
NULLto end the list of named fields, set toPyStructSequence_UnnamedFieldto leave unnamed.
-
const char *doc¶
Field docstring or
NULLto omit.
-
const char *name¶
-
const char *const PyStructSequence_UnnamedField¶
- Part of the Stable ABI since version 3.11.
Спеціальне значення для імені поля, щоб залишити його без імені.
Змінено в версії 3.9: Тип змінено з
char *.
-
PyObject *PyStructSequence_New(PyTypeObject *type)¶
- Return value: New reference. Part of the Stable ABI.
Створює екземпляр type, який має бути створено за допомогою
PyStructSequence_NewType().
-
PyObject *PyStructSequence_GetItem(PyObject *p, Py_ssize_t pos)¶
- Return value: Borrowed reference. Part of the Stable ABI.
Return the object at position pos in the struct sequence pointed to by p. No bounds checking is performed.
-
PyObject *PyStructSequence_GET_ITEM(PyObject *p, Py_ssize_t pos)¶
- Return value: Borrowed reference.
Macro equivalent of
PyStructSequence_GetItem().
-
void PyStructSequence_SetItem(PyObject *p, Py_ssize_t pos, PyObject *o)¶
- Part of the Stable ABI.
Встановлює поле за індексом pos послідовності структур p на значення o. Як і
PyTuple_SET_ITEM(), це слід використовувати лише для заповнення абсолютно нових екземплярів.Примітка
Ця функція «краде» посилання на o.
-
void PyStructSequence_SET_ITEM(PyObject *p, Py_ssize_t *pos, PyObject *o)¶
Similar to
PyStructSequence_SetItem(), but implemented as a static inlined function.Примітка
Ця функція «краде» посилання на o.