mirror of
https://github.com/python/cpython.git
synced 2025-07-23 11:15:24 +00:00

svn+ssh://pythondev@svn.python.org/python/trunk ........ r74074 | georg.brandl | 2009-07-18 05:03:10 -0400 (Sat, 18 Jul 2009) | 1 line #6513: fix example code: warning categories are classes, not instances. ........ r74077 | georg.brandl | 2009-07-18 05:43:40 -0400 (Sat, 18 Jul 2009) | 1 line #6489: fix an ambiguity in getiterator() documentation. ........ r74111 | benjamin.peterson | 2009-07-20 09:30:10 -0400 (Mon, 20 Jul 2009) | 1 line remove docs for deprecated -p option ........ r74188 | benjamin.peterson | 2009-07-23 10:25:31 -0400 (Thu, 23 Jul 2009) | 1 line use bools ........ r74192 | georg.brandl | 2009-07-24 12:28:38 -0400 (Fri, 24 Jul 2009) | 1 line Fix arg types of et#. ........ r74193 | georg.brandl | 2009-07-24 12:46:38 -0400 (Fri, 24 Jul 2009) | 1 line Dont put "void" in signature for nullary functions. ........ r74200 | georg.brandl | 2009-07-25 09:02:15 -0400 (Sat, 25 Jul 2009) | 1 line #6571: add index entries for more operators. ........ r74252 | georg.brandl | 2009-07-29 12:06:31 -0400 (Wed, 29 Jul 2009) | 1 line #6593: fix link targets. ........ r74253 | georg.brandl | 2009-07-29 12:09:17 -0400 (Wed, 29 Jul 2009) | 1 line #6591: add reference to ioctl in fcntl module for platforms other than Windows. ........ r74258 | georg.brandl | 2009-07-29 12:57:05 -0400 (Wed, 29 Jul 2009) | 1 line Add a link to readline, and mention IPython and bpython. ........ r74259 | georg.brandl | 2009-07-29 13:07:21 -0400 (Wed, 29 Jul 2009) | 1 line Fix some markup and small factual glitches found by M. Markert. ........ r74260 | georg.brandl | 2009-07-29 13:15:20 -0400 (Wed, 29 Jul 2009) | 1 line Fix a few markup glitches. ........ r74261 | georg.brandl | 2009-07-29 13:50:25 -0400 (Wed, 29 Jul 2009) | 1 line Rewrite the section about classes a bit; mostly tidbits, and a larger update to the section about "private" variables to reflect the Pythonic consensus better. ........
112 lines
3.4 KiB
ReStructuredText
112 lines
3.4 KiB
ReStructuredText
.. highlightlang:: c
|
|
|
|
.. _tupleobjects:
|
|
|
|
Tuple Objects
|
|
-------------
|
|
|
|
.. index:: object: tuple
|
|
|
|
|
|
.. ctype:: PyTupleObject
|
|
|
|
This subtype of :ctype:`PyObject` represents a Python tuple object.
|
|
|
|
|
|
.. cvar:: PyTypeObject PyTuple_Type
|
|
|
|
.. index:: single: TupleType (in module types)
|
|
|
|
This instance of :ctype:`PyTypeObject` represents the Python tuple type; it is
|
|
the same object as ``tuple`` and ``types.TupleType`` in the Python layer..
|
|
|
|
|
|
.. cfunction:: int PyTuple_Check(PyObject *p)
|
|
|
|
Return true if *p* is a tuple object or an instance of a subtype of the tuple
|
|
type.
|
|
|
|
|
|
.. cfunction:: int PyTuple_CheckExact(PyObject *p)
|
|
|
|
Return true if *p* is a tuple object, but not an instance of a subtype of the
|
|
tuple type.
|
|
|
|
|
|
.. cfunction:: PyObject* PyTuple_New(Py_ssize_t len)
|
|
|
|
Return a new tuple object of size *len*, or *NULL* on failure.
|
|
|
|
|
|
.. cfunction:: PyObject* PyTuple_Pack(Py_ssize_t n, ...)
|
|
|
|
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)``.
|
|
|
|
|
|
.. cfunction:: Py_ssize_t PyTuple_Size(PyObject *p)
|
|
|
|
Take a pointer to a tuple object, and return the size of that tuple.
|
|
|
|
|
|
.. cfunction:: Py_ssize_t PyTuple_GET_SIZE(PyObject *p)
|
|
|
|
Return the size of the tuple *p*, which must be non-*NULL* and point to a tuple;
|
|
no error checking is performed.
|
|
|
|
|
|
.. cfunction:: PyObject* PyTuple_GetItem(PyObject *p, Py_ssize_t pos)
|
|
|
|
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.
|
|
|
|
|
|
.. cfunction:: PyObject* PyTuple_GET_ITEM(PyObject *p, Py_ssize_t pos)
|
|
|
|
Like :cfunc:`PyTuple_GetItem`, but does no checking of its arguments.
|
|
|
|
|
|
.. cfunction:: PyObject* PyTuple_GetSlice(PyObject *p, Py_ssize_t low, Py_ssize_t high)
|
|
|
|
Take a slice of the tuple pointed to by *p* from *low* to *high* and return it
|
|
as a new tuple.
|
|
|
|
|
|
.. cfunction:: int PyTuple_SetItem(PyObject *p, Py_ssize_t pos, PyObject *o)
|
|
|
|
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*.
|
|
|
|
|
|
.. cfunction:: void PyTuple_SET_ITEM(PyObject *p, Py_ssize_t pos, PyObject *o)
|
|
|
|
Like :cfunc:`PyTuple_SetItem`, but does no error checking, and should *only* be
|
|
used to fill in brand new tuples.
|
|
|
|
.. note::
|
|
|
|
This function "steals" a reference to *o*.
|
|
|
|
|
|
.. cfunction:: int _PyTuple_Resize(PyObject **p, Py_ssize_t newsize)
|
|
|
|
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`.
|
|
|
|
|
|
.. cfunction:: int PyTuple_ClearFreeList()
|
|
|
|
Clear the free list. Return the total number of freed items.
|