此子类型的 PyObject represents a Python tuple object.
PyObject
此实例的 PyTypeObject represents the Python tuple type; it is the same object as tuple 在 Python 层。
PyTypeObject
tuple
返回 True 若 p is a tuple object or an instance of a subtype of the tuple type. This function always succeeds.
返回 True 若 p is a tuple object, but not an instance of a subtype of the tuple type. This function always succeeds.
Return a new tuple object of size len ,或 NULL 当故障时。
NULL
Return a new tuple object of size n ,或 NULL on failure. The tuple values are initialized to the subsequent n C arguments pointing to Python objects. PyTuple_Pack(2, a, b) 相当于 Py_BuildValue("(OO)", a, b) .
PyTuple_Pack(2, a, b)
Py_BuildValue("(OO)", a, b)
Take a pointer to a tuple object, and return the size of that tuple.
Return the size of the tuple p , which must be non- NULL and point to a tuple; no error checking is performed.
Return the object at position pos in the tuple pointed to by p 。若 pos is negative or out of bounds, return NULL and set an IndexError 异常。
IndexError
The returned reference is borrowed from the tuple p (that is: it is only valid as long as you hold a reference to p ). To get a 强引用 ,使用 Py_NewRef(PyTuple_GetItem(...)) or PySequence_GetItem() .
Py_NewRef(PyTuple_GetItem(...))
PySequence_GetItem()
像 PyTuple_GetItem() , but does no checking of its arguments.
PyTuple_GetItem()
Return the slice of the tuple pointed to by p between low and high ,或 NULL on failure. This is the equivalent of the Python expression p[low:high] . Indexing from the end of the tuple is not supported.
p[low:high]
Insert a reference to object o 在位置 pos of the tuple pointed to by p 。返回 0 on success. If pos is out of bounds, return -1 and set an IndexError 异常。
0
-1
注意
This function “steals” a reference to o and discards a reference to an item already in the tuple at the affected position.
像 PyTuple_SetItem() , but does no error checking, and should only be used to fill in brand new tuples.
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.
Can be used to resize a tuple. newsize will be the new length of the tuple. Because tuples are supposed to be immutable, this should only be used if there is only one reference to the object. Do not use this if the tuple may already be known to some other part of the code. The tuple will always grow or shrink at the end. Think of this as destroying the old tuple and creating a new one, only more efficiently. Returns 0 on success. Client code should never assume that the resulting value of *p will be the same as before calling this function. If the object referenced by *p is replaced, the original *p is destroyed. On failure, returns -1 并设置 *p to NULL , and raises MemoryError or SystemError .
*p
MemoryError
SystemError
Struct sequence objects are the C equivalent of namedtuple() objects, i.e. a sequence whose items can also be accessed through attributes. To create a struct sequence, you first have to create a specific struct sequence type.
namedtuple()
Create a new struct sequence type from the data in desc , described below. Instances of the resulting type can be created with PyStructSequence_New() .
PyStructSequence_New()
Initializes a struct sequence type type from desc 原位。
如同 PyStructSequence_InitType ,但返回 0 on success and -1 当故障时。
PyStructSequence_InitType
Added in version 3.4.
Contains the meta information of a struct sequence type to create.
Name of the struct sequence type.
Pointer to docstring for the type or NULL to omit.
Pointer to NULL -terminated array with field names of the new type.
Number of fields visible to the Python side (if used as tuple).
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 fields array of the PyStructSequence_Desc determines which field of the struct sequence is described.
fields
PyStructSequence_Desc
Name for the field or NULL to end the list of named fields, set to PyStructSequence_UnnamedField to leave unnamed.
PyStructSequence_UnnamedField
Field docstring or NULL to omit.
Special value for a field name to leave it unnamed.
3.9 版改变: The type was changed from char * .
char *
Creates an instance of type , which must have been created with PyStructSequence_NewType() .
PyStructSequence_NewType()
Return the object at position pos in the struct sequence pointed to by p . No bounds checking is performed.
Macro equivalent of PyStructSequence_GetItem() .
PyStructSequence_GetItem()
Sets the field at index pos of the struct sequence p to value o 。像 PyTuple_SET_ITEM() , this should only be used to fill in brand new instances.
PyTuple_SET_ITEM()
This function “steals” a reference to o .
类似于 PyStructSequence_SetItem() , but implemented as a static inlined function.
PyStructSequence_SetItem()
Unicode 对象和编解码器
列表对象
键入搜索术语或模块、类、函数名称。