2008-01-19 18:08:21 -04:00
|
|
|
.. highlightlang:: c
|
|
|
|
|
|
|
|
.. _tupleobjects:
|
|
|
|
|
|
|
|
Tuple Objects
|
|
|
|
-------------
|
|
|
|
|
|
|
|
.. index:: object: tuple
|
|
|
|
|
|
|
|
|
2012-01-14 11:42:02 -04:00
|
|
|
.. c:type:: PyTupleObject
|
2008-01-19 18:08:21 -04:00
|
|
|
|
2012-01-14 11:42:02 -04:00
|
|
|
This subtype of :c:type:`PyObject` represents a Python tuple object.
|
2008-01-19 18:08:21 -04:00
|
|
|
|
|
|
|
|
2012-01-14 11:42:02 -04:00
|
|
|
.. c:var:: PyTypeObject PyTuple_Type
|
2008-01-19 18:08:21 -04:00
|
|
|
|
|
|
|
.. index:: single: TupleType (in module types)
|
|
|
|
|
2012-01-14 11:42:02 -04:00
|
|
|
This instance of :c:type:`PyTypeObject` represents the Python tuple type; it is
|
2008-01-19 18:08:21 -04:00
|
|
|
the same object as ``tuple`` and ``types.TupleType`` in the Python layer..
|
|
|
|
|
|
|
|
|
2012-01-14 11:42:02 -04:00
|
|
|
.. c:function:: int PyTuple_Check(PyObject *p)
|
2008-01-19 18:08:21 -04:00
|
|
|
|
|
|
|
Return true if *p* is a tuple object or an instance of a subtype of the tuple
|
|
|
|
type.
|
|
|
|
|
|
|
|
.. versionchanged:: 2.2
|
|
|
|
Allowed subtypes to be accepted.
|
|
|
|
|
|
|
|
|
2012-01-14 11:42:02 -04:00
|
|
|
.. c:function:: int PyTuple_CheckExact(PyObject *p)
|
2008-01-19 18:08:21 -04:00
|
|
|
|
|
|
|
Return true if *p* is a tuple object, but not an instance of a subtype of the
|
|
|
|
tuple type.
|
|
|
|
|
|
|
|
.. versionadded:: 2.2
|
|
|
|
|
|
|
|
|
2012-01-14 11:42:02 -04:00
|
|
|
.. c:function:: PyObject* PyTuple_New(Py_ssize_t len)
|
2008-01-19 18:08:21 -04:00
|
|
|
|
|
|
|
Return a new tuple object of size *len*, or *NULL* on failure.
|
|
|
|
|
2009-04-25 14:59:03 -03:00
|
|
|
.. versionchanged:: 2.5
|
2012-01-14 11:42:02 -04:00
|
|
|
This function used an :c:type:`int` type for *len*. This might require
|
2009-04-25 14:59:03 -03:00
|
|
|
changes in your code for properly supporting 64-bit systems.
|
|
|
|
|
2008-01-19 18:08:21 -04:00
|
|
|
|
2012-01-14 11:42:02 -04:00
|
|
|
.. c:function:: PyObject* PyTuple_Pack(Py_ssize_t n, ...)
|
2008-01-19 18:08:21 -04:00
|
|
|
|
|
|
|
Return a new tuple object of size *n*, or *NULL* on failure. The tuple values
|
|
|
|
are initialized to the subsequent *n* C arguments pointing to Python objects.
|
|
|
|
``PyTuple_Pack(2, a, b)`` is equivalent to ``Py_BuildValue("(OO)", a, b)``.
|
|
|
|
|
|
|
|
.. versionadded:: 2.4
|
|
|
|
|
2009-04-25 14:59:03 -03:00
|
|
|
.. versionchanged:: 2.5
|
2012-01-14 11:42:02 -04:00
|
|
|
This function used an :c:type:`int` type for *n*. This might require
|
2009-04-25 14:59:03 -03:00
|
|
|
changes in your code for properly supporting 64-bit systems.
|
|
|
|
|
2008-01-19 18:08:21 -04:00
|
|
|
|
2012-01-14 11:42:02 -04:00
|
|
|
.. c:function:: Py_ssize_t PyTuple_Size(PyObject *p)
|
2008-01-19 18:08:21 -04:00
|
|
|
|
|
|
|
Take a pointer to a tuple object, and return the size of that tuple.
|
|
|
|
|
2009-04-25 14:59:03 -03:00
|
|
|
.. versionchanged:: 2.5
|
2012-01-14 11:42:02 -04:00
|
|
|
This function returned an :c:type:`int` type. This might require changes
|
2009-04-25 14:59:03 -03:00
|
|
|
in your code for properly supporting 64-bit systems.
|
|
|
|
|
2008-01-19 18:08:21 -04:00
|
|
|
|
2012-01-14 11:42:02 -04:00
|
|
|
.. c:function:: Py_ssize_t PyTuple_GET_SIZE(PyObject *p)
|
2008-01-19 18:08:21 -04:00
|
|
|
|
|
|
|
Return the size of the tuple *p*, which must be non-*NULL* and point to a tuple;
|
|
|
|
no error checking is performed.
|
|
|
|
|
2009-04-25 17:58:35 -03:00
|
|
|
.. versionchanged:: 2.5
|
2012-01-14 11:42:02 -04:00
|
|
|
This function returned an :c:type:`int` type. This might require changes
|
2009-04-25 17:58:35 -03:00
|
|
|
in your code for properly supporting 64-bit systems.
|
|
|
|
|
2008-01-19 18:08:21 -04:00
|
|
|
|
2012-01-14 11:42:02 -04:00
|
|
|
.. c:function:: PyObject* PyTuple_GetItem(PyObject *p, Py_ssize_t pos)
|
2008-01-19 18:08:21 -04:00
|
|
|
|
|
|
|
Return the object at position *pos* in the tuple pointed to by *p*. If *pos* is
|
|
|
|
out of bounds, return *NULL* and sets an :exc:`IndexError` exception.
|
|
|
|
|
2009-04-25 14:59:03 -03:00
|
|
|
.. versionchanged:: 2.5
|
2012-01-14 11:42:02 -04:00
|
|
|
This function used an :c:type:`int` type for *pos*. This might require
|
2009-04-25 14:59:03 -03:00
|
|
|
changes in your code for properly supporting 64-bit systems.
|
|
|
|
|
2008-01-19 18:08:21 -04:00
|
|
|
|
2012-01-14 11:42:02 -04:00
|
|
|
.. c:function:: PyObject* PyTuple_GET_ITEM(PyObject *p, Py_ssize_t pos)
|
2008-01-19 18:08:21 -04:00
|
|
|
|
2012-01-14 11:42:02 -04:00
|
|
|
Like :c:func:`PyTuple_GetItem`, but does no checking of its arguments.
|
2008-01-19 18:08:21 -04:00
|
|
|
|
2009-04-25 17:58:35 -03:00
|
|
|
.. versionchanged:: 2.5
|
2012-01-14 11:42:02 -04:00
|
|
|
This function used an :c:type:`int` type for *pos*. This might require
|
2009-04-25 17:58:35 -03:00
|
|
|
changes in your code for properly supporting 64-bit systems.
|
|
|
|
|
2008-01-19 18:08:21 -04:00
|
|
|
|
2012-01-14 11:42:02 -04:00
|
|
|
.. c:function:: PyObject* PyTuple_GetSlice(PyObject *p, Py_ssize_t low, Py_ssize_t high)
|
2008-01-19 18:08:21 -04:00
|
|
|
|
|
|
|
Take a slice of the tuple pointed to by *p* from *low* to *high* and return it
|
|
|
|
as a new tuple.
|
|
|
|
|
2009-04-25 14:59:03 -03:00
|
|
|
.. versionchanged:: 2.5
|
2012-01-14 11:42:02 -04:00
|
|
|
This function used an :c:type:`int` type for *low* and *high*. This might
|
2009-04-25 14:59:03 -03:00
|
|
|
require changes in your code for properly supporting 64-bit systems.
|
|
|
|
|
2008-01-19 18:08:21 -04:00
|
|
|
|
2012-01-14 11:42:02 -04:00
|
|
|
.. c:function:: int PyTuple_SetItem(PyObject *p, Py_ssize_t pos, PyObject *o)
|
2008-01-19 18:08:21 -04:00
|
|
|
|
|
|
|
Insert a reference to object *o* at position *pos* of the tuple pointed to by
|
|
|
|
*p*. Return ``0`` on success.
|
|
|
|
|
|
|
|
.. note::
|
|
|
|
|
|
|
|
This function "steals" a reference to *o*.
|
|
|
|
|
2009-04-25 14:59:03 -03:00
|
|
|
.. versionchanged:: 2.5
|
2012-01-14 11:42:02 -04:00
|
|
|
This function used an :c:type:`int` type for *pos*. This might require
|
2009-04-25 14:59:03 -03:00
|
|
|
changes in your code for properly supporting 64-bit systems.
|
|
|
|
|
2008-01-19 18:08:21 -04:00
|
|
|
|
2012-01-14 11:42:02 -04:00
|
|
|
.. c:function:: void PyTuple_SET_ITEM(PyObject *p, Py_ssize_t pos, PyObject *o)
|
2008-01-19 18:08:21 -04:00
|
|
|
|
2012-01-14 11:42:02 -04:00
|
|
|
Like :c:func:`PyTuple_SetItem`, but does no error checking, and should *only* be
|
2008-01-19 18:08:21 -04:00
|
|
|
used to fill in brand new tuples.
|
|
|
|
|
|
|
|
.. note::
|
|
|
|
|
|
|
|
This function "steals" a reference to *o*.
|
|
|
|
|
2009-04-25 17:58:35 -03:00
|
|
|
.. versionchanged:: 2.5
|
2012-01-14 11:42:02 -04:00
|
|
|
This function used an :c:type:`int` type for *pos*. This might require
|
2009-04-25 17:58:35 -03:00
|
|
|
changes in your code for properly supporting 64-bit systems.
|
|
|
|
|
2008-01-19 18:08:21 -04:00
|
|
|
|
2012-01-14 11:42:02 -04:00
|
|
|
.. c:function:: int _PyTuple_Resize(PyObject **p, Py_ssize_t newsize)
|
2008-01-19 18:08:21 -04:00
|
|
|
|
|
|
|
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`` and sets ``*p`` to *NULL*, and
|
|
|
|
raises :exc:`MemoryError` or :exc:`SystemError`.
|
|
|
|
|
|
|
|
.. versionchanged:: 2.2
|
|
|
|
Removed unused third parameter, *last_is_sticky*.
|
2008-02-14 08:47:33 -04:00
|
|
|
|
2009-04-25 14:59:03 -03:00
|
|
|
.. versionchanged:: 2.5
|
2012-01-14 11:42:02 -04:00
|
|
|
This function used an :c:type:`int` type for *newsize*. This might
|
2009-04-25 14:59:03 -03:00
|
|
|
require changes in your code for properly supporting 64-bit systems.
|
|
|
|
|
2008-02-14 08:47:33 -04:00
|
|
|
|
2012-01-14 11:42:02 -04:00
|
|
|
.. c:function:: int PyTuple_ClearFreeList()
|
2008-02-14 08:47:33 -04:00
|
|
|
|
|
|
|
Clear the free list. Return the total number of freed items.
|
|
|
|
|
|
|
|
.. versionadded:: 2.6
|