| 1 | <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> |
| 2 | <html> |
| 3 | <head> |
| 4 | <link rel="STYLESHEET" href="api.css" type='text/css' /> |
| 5 | <link rel="SHORTCUT ICON" href="../icons/pyfav.png" type="image/png" /> |
| 6 | <link rel='start' href='../index.html' title='Python Documentation Index' /> |
| 7 | <link rel="first" href="api.html" title='Python/C API Reference Manual' /> |
| 8 | <link rel='contents' href='contents.html' title="Contents" /> |
| 9 | <link rel='index' href='genindex.html' title='Index' /> |
| 10 | <link rel='last' href='about.html' title='About this document...' /> |
| 11 | <link rel='help' href='about.html' title='About this document...' /> |
| 12 | <link rel="next" href="listObjects.html" /> |
| 13 | <link rel="prev" href="bufferObjects.html" /> |
| 14 | <link rel="parent" href="sequenceObjects.html" /> |
| 15 | <link rel="next" href="listObjects.html" /> |
| 16 | <meta name='aesop' content='information' /> |
| 17 | <title>7.3.4 Tuple Objects </title> |
| 18 | </head> |
| 19 | <body> |
| 20 | <DIV CLASS="navigation"> |
| 21 | <div id='top-navigation-panel' xml:id='top-navigation-panel'> |
| 22 | <table align="center" width="100%" cellpadding="0" cellspacing="2"> |
| 23 | <tr> |
| 24 | <td class='online-navigation'><a rel="prev" title="7.3.3 Buffer Objects" |
| 25 | href="bufferObjects.html"><img src='../icons/previous.png' |
| 26 | border='0' height='32' alt='Previous Page' width='32' /></A></td> |
| 27 | <td class='online-navigation'><a rel="parent" title="7.3 Sequence Objects" |
| 28 | href="sequenceObjects.html"><img src='../icons/up.png' |
| 29 | border='0' height='32' alt='Up One Level' width='32' /></A></td> |
| 30 | <td class='online-navigation'><a rel="next" title="7.3.5 List Objects" |
| 31 | href="listObjects.html"><img src='../icons/next.png' |
| 32 | border='0' height='32' alt='Next Page' width='32' /></A></td> |
| 33 | <td align="center" width="100%">Python/C API Reference Manual</td> |
| 34 | <td class='online-navigation'><a rel="contents" title="Table of Contents" |
| 35 | href="contents.html"><img src='../icons/contents.png' |
| 36 | border='0' height='32' alt='Contents' width='32' /></A></td> |
| 37 | <td class='online-navigation'><img src='../icons/blank.png' |
| 38 | border='0' height='32' alt='' width='32' /></td> |
| 39 | <td class='online-navigation'><a rel="index" title="Index" |
| 40 | href="genindex.html"><img src='../icons/index.png' |
| 41 | border='0' height='32' alt='Index' width='32' /></A></td> |
| 42 | </tr></table> |
| 43 | <div class='online-navigation'> |
| 44 | <b class="navlabel">Previous:</b> |
| 45 | <a class="sectref" rel="prev" href="bufferObjects.html">7.3.3 Buffer Objects</A> |
| 46 | <b class="navlabel">Up:</b> |
| 47 | <a class="sectref" rel="parent" href="sequenceObjects.html">7.3 Sequence Objects</A> |
| 48 | <b class="navlabel">Next:</b> |
| 49 | <a class="sectref" rel="next" href="listObjects.html">7.3.5 List Objects</A> |
| 50 | </div> |
| 51 | <hr /></div> |
| 52 | </DIV> |
| 53 | <!--End of Navigation Panel--> |
| 54 | |
| 55 | <H2><A NAME="SECTION009340000000000000000"></A><A NAME="tupleObjects"></A> |
| 56 | <BR> |
| 57 | 7.3.4 Tuple Objects |
| 58 | </H2> |
| 59 | |
| 60 | <P> |
| 61 | <a id='l2h-562' xml:id='l2h-562'></a><dl><dt><b><tt class="ctype"><a id='l2h-563' xml:id='l2h-563'>PyTupleObject</a></tt></b></dt> |
| 62 | <dd> |
| 63 | This subtype of <tt class="ctype">PyObject</tt> represents a Python tuple object. |
| 64 | </dl> |
| 65 | |
| 66 | <P> |
| 67 | <dl><dt>PyTypeObject <b><tt id='l2h-564' xml:id='l2h-564' class="cdata">PyTuple_Type</tt></b></dt> |
| 68 | <dd> |
| 69 | This instance of <tt class="ctype">PyTypeObject</tt> represents the Python tuple |
| 70 | type; it is the same object as <code>types.TupleType</code> in the Python |
| 71 | layer.<a id='l2h-566' xml:id='l2h-566'></a>. |
| 72 | </dd></dl> |
| 73 | |
| 74 | <P> |
| 75 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"><td><nobr>int <b><tt id='l2h-567' xml:id='l2h-567' class="cfunction">PyTuple_Check</tt></b>(</nobr></td><td>PyObject *<var>p</var>)</td></tr></table></dt> |
| 76 | <dd> |
| 77 | Return true if <var>p</var> is a tuple object or an instance of a subtype |
| 78 | of the tuple type. |
| 79 | |
| 80 | <span class="versionnote">Changed in version 2.2: |
| 81 | Allowed subtypes to be accepted.</span> |
| 82 | |
| 83 | </dd></dl> |
| 84 | |
| 85 | <P> |
| 86 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"><td><nobr>int <b><tt id='l2h-568' xml:id='l2h-568' class="cfunction">PyTuple_CheckExact</tt></b>(</nobr></td><td>PyObject *<var>p</var>)</td></tr></table></dt> |
| 87 | <dd> |
| 88 | Return true if <var>p</var> is a tuple object, but not an instance of a |
| 89 | subtype of the tuple type. |
| 90 | |
| 91 | <span class="versionnote">New in version 2.2.</span> |
| 92 | |
| 93 | </dd></dl> |
| 94 | |
| 95 | <P> |
| 96 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"><td><nobr>PyObject* <b><tt id='l2h-569' xml:id='l2h-569' class="cfunction">PyTuple_New</tt></b>(</nobr></td><td>int <var>len</var>)</td></tr></table></dt> |
| 97 | <dd> |
| 98 | <div class="refcount-info"> |
| 99 | <span class="label">Return value:</span> |
| 100 | <span class="value">New reference.</span> |
| 101 | </div> |
| 102 | Return a new tuple object of size <var>len</var>, or <tt class="constant">NULL</tt> on failure. |
| 103 | </dd></dl> |
| 104 | |
| 105 | <P> |
| 106 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"><td><nobr>PyObject* <b><tt id='l2h-570' xml:id='l2h-570' class="cfunction">PyTuple_Pack</tt></b>(</nobr></td><td>int <var>n</var>, ...)</td></tr></table></dt> |
| 107 | <dd> |
| 108 | Return a new tuple object of size <var>n</var>, or <tt class="constant">NULL</tt> on failure. |
| 109 | The tuple values are initialized to the subsequent <var>n</var> C arguments |
| 110 | pointing to Python objects. "<tt class="samp">PyTuple_Pack(2, <var>a</var>, <var>b</var>)</tt>" is equivalent to "<tt class="samp">Py_BuildValue("(OO)", <var>a</var>, <var>b</var>)</tt>". |
| 111 | |
| 112 | <span class="versionnote">New in version 2.4.</span> |
| 113 | |
| 114 | </dd></dl> |
| 115 | |
| 116 | <P> |
| 117 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"><td><nobr>int <b><tt id='l2h-571' xml:id='l2h-571' class="cfunction">PyTuple_Size</tt></b>(</nobr></td><td>PyObject *<var>p</var>)</td></tr></table></dt> |
| 118 | <dd> |
| 119 | Take a pointer to a tuple object, and return the size of that |
| 120 | tuple. |
| 121 | </dd></dl> |
| 122 | |
| 123 | <P> |
| 124 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"><td><nobr>int <b><tt id='l2h-572' xml:id='l2h-572' class="cfunction">PyTuple_GET_SIZE</tt></b>(</nobr></td><td>PyObject *<var>p</var>)</td></tr></table></dt> |
| 125 | <dd> |
| 126 | Return the size of the tuple <var>p</var>, which must be non-<tt class="constant">NULL</tt> and |
| 127 | point to a tuple; no error checking is performed. |
| 128 | </dd></dl> |
| 129 | |
| 130 | <P> |
| 131 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"><td><nobr>PyObject* <b><tt id='l2h-573' xml:id='l2h-573' class="cfunction">PyTuple_GetItem</tt></b>(</nobr></td><td>PyObject *<var>p</var>, int <var>pos</var>)</td></tr></table></dt> |
| 132 | <dd> |
| 133 | <div class="refcount-info"> |
| 134 | <span class="label">Return value:</span> |
| 135 | <span class="value">Borrowed reference.</span> |
| 136 | </div> |
| 137 | Return the object at position <var>pos</var> in the tuple pointed to by |
| 138 | <var>p</var>. If <var>pos</var> is out of bounds, return <tt class="constant">NULL</tt> and sets an |
| 139 | <tt class="exception">IndexError</tt> exception. |
| 140 | </dd></dl> |
| 141 | |
| 142 | <P> |
| 143 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"><td><nobr>PyObject* <b><tt id='l2h-574' xml:id='l2h-574' class="cfunction">PyTuple_GET_ITEM</tt></b>(</nobr></td><td>PyObject *<var>p</var>, int <var>pos</var>)</td></tr></table></dt> |
| 144 | <dd> |
| 145 | <div class="refcount-info"> |
| 146 | <span class="label">Return value:</span> |
| 147 | <span class="value">Borrowed reference.</span> |
| 148 | </div> |
| 149 | Like <tt class="cfunction">PyTuple_GetItem()</tt>, but does no checking of its |
| 150 | arguments. |
| 151 | </dd></dl> |
| 152 | |
| 153 | <P> |
| 154 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"><td><nobr>PyObject* <b><tt id='l2h-575' xml:id='l2h-575' class="cfunction">PyTuple_GetSlice</tt></b>(</nobr></td><td>PyObject *<var>p</var>, |
| 155 | int <var>low</var>, int <var>high</var>)</td></tr></table></dt> |
| 156 | <dd> |
| 157 | <div class="refcount-info"> |
| 158 | <span class="label">Return value:</span> |
| 159 | <span class="value">New reference.</span> |
| 160 | </div> |
| 161 | Take a slice of the tuple pointed to by <var>p</var> from <var>low</var> to |
| 162 | <var>high</var> and return it as a new tuple. |
| 163 | </dd></dl> |
| 164 | |
| 165 | <P> |
| 166 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"><td><nobr>int <b><tt id='l2h-576' xml:id='l2h-576' class="cfunction">PyTuple_SetItem</tt></b>(</nobr></td><td>PyObject *<var>p</var>, |
| 167 | int <var>pos</var>, PyObject *<var>o</var>)</td></tr></table></dt> |
| 168 | <dd> |
| 169 | Insert a reference to object <var>o</var> at position <var>pos</var> of the |
| 170 | tuple pointed to by <var>p</var>. Return <code>0</code> on success. |
| 171 | <span class="note"><b class="label">Note:</b> |
| 172 | This function ``steals'' a reference to <var>o</var>.</span> |
| 173 | </dd></dl> |
| 174 | |
| 175 | <P> |
| 176 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"><td><nobr>void <b><tt id='l2h-577' xml:id='l2h-577' class="cfunction">PyTuple_SET_ITEM</tt></b>(</nobr></td><td>PyObject *<var>p</var>, |
| 177 | int <var>pos</var>, PyObject *<var>o</var>)</td></tr></table></dt> |
| 178 | <dd> |
| 179 | Like <tt class="cfunction">PyTuple_SetItem()</tt>, but does no error checking, and |
| 180 | should <em>only</em> be used to fill in brand new tuples. <span class="note"><b class="label">Note:</b> |
| 181 | This |
| 182 | function ``steals'' a reference to <var>o</var>.</span> |
| 183 | </dd></dl> |
| 184 | |
| 185 | <P> |
| 186 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"><td><nobr>int <b><tt id='l2h-578' xml:id='l2h-578' class="cfunction">_PyTuple_Resize</tt></b>(</nobr></td><td>PyObject **<var>p</var>, int <var>newsize</var>)</td></tr></table></dt> |
| 187 | <dd> |
| 188 | Can be used to resize a tuple. <var>newsize</var> will be the new length |
| 189 | of the tuple. Because tuples are <em>supposed</em> to be immutable, |
| 190 | this should only be used if there is only one reference to the |
| 191 | object. Do <em>not</em> use this if the tuple may already be known to |
| 192 | some other part of the code. The tuple will always grow or shrink |
| 193 | at the end. Think of this as destroying the old tuple and creating |
| 194 | a new one, only more efficiently. Returns <code>0</code> on success. |
| 195 | Client code should never assume that the resulting value of |
| 196 | <code>*<var>p</var></code> will be the same as before calling this function. |
| 197 | If the object referenced by <code>*<var>p</var></code> is replaced, the |
| 198 | original <code>*<var>p</var></code> is destroyed. On failure, returns |
| 199 | <code>-1</code> and sets <code>*<var>p</var></code> to <tt class="constant">NULL</tt>, and raises |
| 200 | <tt class="exception">MemoryError</tt> or |
| 201 | <tt class="exception">SystemError</tt>. |
| 202 | |
| 203 | <span class="versionnote">Changed in version 2.2: |
| 204 | Removed unused third parameter, <var>last_is_sticky</var>.</span> |
| 205 | |
| 206 | </dd></dl> |
| 207 | |
| 208 | <P> |
| 209 | |
| 210 | <DIV CLASS="navigation"> |
| 211 | <div class='online-navigation'> |
| 212 | <p></p><hr /> |
| 213 | <table align="center" width="100%" cellpadding="0" cellspacing="2"> |
| 214 | <tr> |
| 215 | <td class='online-navigation'><a rel="prev" title="7.3.3 Buffer Objects" |
| 216 | href="bufferObjects.html"><img src='../icons/previous.png' |
| 217 | border='0' height='32' alt='Previous Page' width='32' /></A></td> |
| 218 | <td class='online-navigation'><a rel="parent" title="7.3 Sequence Objects" |
| 219 | href="sequenceObjects.html"><img src='../icons/up.png' |
| 220 | border='0' height='32' alt='Up One Level' width='32' /></A></td> |
| 221 | <td class='online-navigation'><a rel="next" title="7.3.5 List Objects" |
| 222 | href="listObjects.html"><img src='../icons/next.png' |
| 223 | border='0' height='32' alt='Next Page' width='32' /></A></td> |
| 224 | <td align="center" width="100%">Python/C API Reference Manual</td> |
| 225 | <td class='online-navigation'><a rel="contents" title="Table of Contents" |
| 226 | href="contents.html"><img src='../icons/contents.png' |
| 227 | border='0' height='32' alt='Contents' width='32' /></A></td> |
| 228 | <td class='online-navigation'><img src='../icons/blank.png' |
| 229 | border='0' height='32' alt='' width='32' /></td> |
| 230 | <td class='online-navigation'><a rel="index" title="Index" |
| 231 | href="genindex.html"><img src='../icons/index.png' |
| 232 | border='0' height='32' alt='Index' width='32' /></A></td> |
| 233 | </tr></table> |
| 234 | <div class='online-navigation'> |
| 235 | <b class="navlabel">Previous:</b> |
| 236 | <a class="sectref" rel="prev" href="bufferObjects.html">7.3.3 Buffer Objects</A> |
| 237 | <b class="navlabel">Up:</b> |
| 238 | <a class="sectref" rel="parent" href="sequenceObjects.html">7.3 Sequence Objects</A> |
| 239 | <b class="navlabel">Next:</b> |
| 240 | <a class="sectref" rel="next" href="listObjects.html">7.3.5 List Objects</A> |
| 241 | </div> |
| 242 | </div> |
| 243 | <hr /> |
| 244 | <span class="release-info">Release 2.4.2, documentation updated on 28 September 2005.</span> |
| 245 | </DIV> |
| 246 | <!--End of Navigation Panel--> |
| 247 | <ADDRESS> |
| 248 | See <i><a href="about.html">About this document...</a></i> for information on suggesting changes. |
| 249 | </ADDRESS> |
| 250 | </BODY> |
| 251 | </HTML> |