Initial commit of OpenSPARC T2 architecture model.
[OpenSPARC-T2-SAM] / sam-t2 / devtools / amd64 / html / python / api / sequence.html
CommitLineData
920dae64
AT
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="mapping.html" />
13<link rel="prev" href="number.html" />
14<link rel="parent" href="abstract.html" />
15<link rel="next" href="mapping.html" />
16<meta name='aesop' content='information' />
17<title>6.3 Sequence Protocol </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="6.2 Number Protocol"
25 href="number.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="6. Abstract Objects Layer"
28 href="abstract.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="6.4 Mapping Protocol"
31 href="mapping.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="number.html">6.2 Number Protocol</A>
46<b class="navlabel">Up:</b>
47<a class="sectref" rel="parent" href="abstract.html">6. Abstract Objects Layer</A>
48<b class="navlabel">Next:</b>
49<a class="sectref" rel="next" href="mapping.html">6.4 Mapping Protocol</A>
50</div>
51<hr /></div>
52</DIV>
53<!--End of Navigation Panel-->
54
55<H1><A NAME="SECTION008300000000000000000"></A><A NAME="sequence"></A>
56<BR>
576.3 Sequence Protocol
58</H1>
59
60<P>
61<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"><td><nobr>int&nbsp;<b><tt id='l2h-308' xml:id='l2h-308' class="cfunction">PySequence_Check</tt></b>(</nobr></td><td>PyObject *<var>o</var>)</td></tr></table></dt>
62<dd>
63 Return <code>1</code> if the object provides sequence protocol, and
64 <code>0</code> otherwise. This function always succeeds.
65</dd></dl>
66
67<P>
68<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"><td><nobr>int&nbsp;<b><tt id='l2h-309' xml:id='l2h-309' class="cfunction">PySequence_Size</tt></b>(</nobr></td><td>PyObject *<var>o</var>)</td></tr></table></dt>
69<dd>
70 Returns the number of objects in sequence <var>o</var> on success, and
71 <code>-1</code> on failure. For objects that do not provide sequence
72 protocol, this is equivalent to the Python expression
73 "<tt class="samp">len(<var>o</var>)</tt>".<a id='l2h-310' xml:id='l2h-310'></a></dd></dl>
74
75<P>
76<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"><td><nobr>int&nbsp;<b><tt id='l2h-311' xml:id='l2h-311' class="cfunction">PySequence_Length</tt></b>(</nobr></td><td>PyObject *<var>o</var>)</td></tr></table></dt>
77<dd>
78 Alternate name for <tt class="cfunction">PySequence_Size()</tt>.
79</dd></dl>
80
81<P>
82<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"><td><nobr>PyObject*&nbsp;<b><tt id='l2h-312' xml:id='l2h-312' class="cfunction">PySequence_Concat</tt></b>(</nobr></td><td>PyObject *<var>o1</var>, PyObject *<var>o2</var>)</td></tr></table></dt>
83<dd>
84<div class="refcount-info">
85 <span class="label">Return value:</span>
86 <span class="value">New reference.</span>
87</div>
88 Return the concatenation of <var>o1</var> and <var>o2</var> on success, and
89 <tt class="constant">NULL</tt> on failure. This is the equivalent of the Python
90 expression "<tt class="samp"><var>o1</var> + <var>o2</var></tt>".
91</dd></dl>
92
93<P>
94<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"><td><nobr>PyObject*&nbsp;<b><tt id='l2h-313' xml:id='l2h-313' class="cfunction">PySequence_Repeat</tt></b>(</nobr></td><td>PyObject *<var>o</var>, int <var>count</var>)</td></tr></table></dt>
95<dd>
96<div class="refcount-info">
97 <span class="label">Return value:</span>
98 <span class="value">New reference.</span>
99</div>
100 Return the result of repeating sequence object <var>o</var> <var>count</var>
101 times, or <tt class="constant">NULL</tt> on failure. This is the equivalent of the Python
102 expression "<tt class="samp"><var>o</var> * <var>count</var></tt>".
103</dd></dl>
104
105<P>
106<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"><td><nobr>PyObject*&nbsp;<b><tt id='l2h-314' xml:id='l2h-314' class="cfunction">PySequence_InPlaceConcat</tt></b>(</nobr></td><td>PyObject *<var>o1</var>,
107 PyObject *<var>o2</var>)</td></tr></table></dt>
108<dd>
109<div class="refcount-info">
110 <span class="label">Return value:</span>
111 <span class="value">New reference.</span>
112</div>
113 Return the concatenation of <var>o1</var> and <var>o2</var> on success, and
114 <tt class="constant">NULL</tt> on failure. The operation is done <em>in-place</em> when
115 <var>o1</var> supports it. This is the equivalent of the Python
116 expression "<tt class="samp"><var>o1</var> += <var>o2</var></tt>".
117</dd></dl>
118
119<P>
120<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"><td><nobr>PyObject*&nbsp;<b><tt id='l2h-315' xml:id='l2h-315' class="cfunction">PySequence_InPlaceRepeat</tt></b>(</nobr></td><td>PyObject *<var>o</var>, int <var>count</var>)</td></tr></table></dt>
121<dd>
122<div class="refcount-info">
123 <span class="label">Return value:</span>
124 <span class="value">New reference.</span>
125</div>
126 Return the result of repeating sequence object <var>o</var> <var>count</var>
127 times, or <tt class="constant">NULL</tt> on failure. The operation is done <em>in-place</em>
128 when <var>o</var> supports it. This is the equivalent of the Python
129 expression "<tt class="samp"><var>o</var> *= <var>count</var></tt>".
130</dd></dl>
131
132<P>
133<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"><td><nobr>PyObject*&nbsp;<b><tt id='l2h-316' xml:id='l2h-316' class="cfunction">PySequence_GetItem</tt></b>(</nobr></td><td>PyObject *<var>o</var>, int <var>i</var>)</td></tr></table></dt>
134<dd>
135<div class="refcount-info">
136 <span class="label">Return value:</span>
137 <span class="value">New reference.</span>
138</div>
139 Return the <var>i</var>th element of <var>o</var>, or <tt class="constant">NULL</tt> on failure.
140 This is the equivalent of the Python expression
141 "<tt class="samp"><var>o</var>[<var>i</var>]</tt>".
142</dd></dl>
143
144<P>
145<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"><td><nobr>PyObject*&nbsp;<b><tt id='l2h-317' xml:id='l2h-317' class="cfunction">PySequence_GetSlice</tt></b>(</nobr></td><td>PyObject *<var>o</var>, int <var>i1</var>, int <var>i2</var>)</td></tr></table></dt>
146<dd>
147<div class="refcount-info">
148 <span class="label">Return value:</span>
149 <span class="value">New reference.</span>
150</div>
151 Return the slice of sequence object <var>o</var> between <var>i1</var> and
152 <var>i2</var>, or <tt class="constant">NULL</tt> on failure. This is the equivalent of the
153 Python expression "<tt class="samp"><var>o</var>[<var>i1</var>:<var>i2</var>]</tt>".
154</dd></dl>
155
156<P>
157<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"><td><nobr>int&nbsp;<b><tt id='l2h-318' xml:id='l2h-318' class="cfunction">PySequence_SetItem</tt></b>(</nobr></td><td>PyObject *<var>o</var>, int <var>i</var>, PyObject *<var>v</var>)</td></tr></table></dt>
158<dd>
159 Assign object <var>v</var> to the <var>i</var>th element of <var>o</var>. Returns
160 <code>-1</code> on failure. This is the equivalent of the Python
161 statement "<tt class="samp"><var>o</var>[<var>i</var>] = <var>v</var></tt>". This function <em>does not</em>
162 steal a reference to <var>v</var>.
163</dd></dl>
164
165<P>
166<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"><td><nobr>int&nbsp;<b><tt id='l2h-319' xml:id='l2h-319' class="cfunction">PySequence_DelItem</tt></b>(</nobr></td><td>PyObject *<var>o</var>, int <var>i</var>)</td></tr></table></dt>
167<dd>
168 Delete the <var>i</var>th element of object <var>o</var>. Returns <code>-1</code>
169 on failure. This is the equivalent of the Python statement
170 "<tt class="samp">del <var>o</var>[<var>i</var>]</tt>".
171</dd></dl>
172
173<P>
174<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"><td><nobr>int&nbsp;<b><tt id='l2h-320' xml:id='l2h-320' class="cfunction">PySequence_SetSlice</tt></b>(</nobr></td><td>PyObject *<var>o</var>, int <var>i1</var>,
175 int <var>i2</var>, PyObject *<var>v</var>)</td></tr></table></dt>
176<dd>
177 Assign the sequence object <var>v</var> to the slice in sequence object
178 <var>o</var> from <var>i1</var> to <var>i2</var>. This is the equivalent of the
179 Python statement "<tt class="samp"><var>o</var>[<var>i1</var>:<var>i2</var>] = <var>v</var></tt>".
180</dd></dl>
181
182<P>
183<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"><td><nobr>int&nbsp;<b><tt id='l2h-321' xml:id='l2h-321' class="cfunction">PySequence_DelSlice</tt></b>(</nobr></td><td>PyObject *<var>o</var>, int <var>i1</var>, int <var>i2</var>)</td></tr></table></dt>
184<dd>
185 Delete the slice in sequence object <var>o</var> from <var>i1</var> to
186 <var>i2</var>. Returns <code>-1</code> on failure. This is the equivalent of
187 the Python statement "<tt class="samp">del <var>o</var>[<var>i1</var>:<var>i2</var>]</tt>".
188</dd></dl>
189
190<P>
191<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"><td><nobr>PyObject*&nbsp;<b><tt id='l2h-322' xml:id='l2h-322' class="cfunction">PySequence_Tuple</tt></b>(</nobr></td><td>PyObject *<var>o</var>)</td></tr></table></dt>
192<dd>
193<div class="refcount-info">
194 <span class="label">Return value:</span>
195 <span class="value">New reference.</span>
196</div>
197 Returns the <var>o</var> as a tuple on success, and <tt class="constant">NULL</tt> on failure.
198 This is equivalent to the Python expression "<tt class="samp">tuple(<var>o</var>)</tt>".
199 <a id='l2h-323' xml:id='l2h-323'></a></dd></dl>
200
201<P>
202<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"><td><nobr>int&nbsp;<b><tt id='l2h-324' xml:id='l2h-324' class="cfunction">PySequence_Count</tt></b>(</nobr></td><td>PyObject *<var>o</var>, PyObject *<var>value</var>)</td></tr></table></dt>
203<dd>
204 Return the number of occurrences of <var>value</var> in <var>o</var>, that is,
205 return the number of keys for which <code><var>o</var>[<var>key</var>] ==
206 <var>value</var></code>. On failure, return <code>-1</code>. This is equivalent to
207 the Python expression "<tt class="samp"><var>o</var>.count(<var>value</var>)</tt>".
208</dd></dl>
209
210<P>
211<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"><td><nobr>int&nbsp;<b><tt id='l2h-325' xml:id='l2h-325' class="cfunction">PySequence_Contains</tt></b>(</nobr></td><td>PyObject *<var>o</var>, PyObject *<var>value</var>)</td></tr></table></dt>
212<dd>
213 Determine if <var>o</var> contains <var>value</var>. If an item in <var>o</var> is
214 equal to <var>value</var>, return <code>1</code>, otherwise return <code>0</code>.
215 On error, return <code>-1</code>. This is equivalent to the Python
216 expression "<tt class="samp"><var>value</var> in <var>o</var></tt>".
217</dd></dl>
218
219<P>
220<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"><td><nobr>int&nbsp;<b><tt id='l2h-326' xml:id='l2h-326' class="cfunction">PySequence_Index</tt></b>(</nobr></td><td>PyObject *<var>o</var>, PyObject *<var>value</var>)</td></tr></table></dt>
221<dd>
222 Return the first index <var>i</var> for which <code><var>o</var>[<var>i</var>] ==
223 <var>value</var></code>. On error, return <code>-1</code>. This is equivalent to
224 the Python expression "<tt class="samp"><var>o</var>.index(<var>value</var>)</tt>".
225</dd></dl>
226
227<P>
228<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"><td><nobr>PyObject*&nbsp;<b><tt id='l2h-327' xml:id='l2h-327' class="cfunction">PySequence_List</tt></b>(</nobr></td><td>PyObject *<var>o</var>)</td></tr></table></dt>
229<dd>
230<div class="refcount-info">
231 <span class="label">Return value:</span>
232 <span class="value">New reference.</span>
233</div>
234 Return a list object with the same contents as the arbitrary
235 sequence <var>o</var>. The returned list is guaranteed to be new.
236</dd></dl>
237
238<P>
239<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"><td><nobr>PyObject*&nbsp;<b><tt id='l2h-328' xml:id='l2h-328' class="cfunction">PySequence_Tuple</tt></b>(</nobr></td><td>PyObject *<var>o</var>)</td></tr></table></dt>
240<dd>
241<div class="refcount-info">
242 <span class="label">Return value:</span>
243 <span class="value">New reference.</span>
244</div>
245 Return a tuple object with the same contents as the arbitrary
246 sequence <var>o</var>. If <var>o</var> is a tuple, a new reference will be
247 returned, otherwise a tuple will be constructed with the appropriate
248 contents.
249</dd></dl>
250
251<P>
252<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"><td><nobr>PyObject*&nbsp;<b><tt id='l2h-329' xml:id='l2h-329' class="cfunction">PySequence_Fast</tt></b>(</nobr></td><td>PyObject *<var>o</var>, const char *<var>m</var>)</td></tr></table></dt>
253<dd>
254<div class="refcount-info">
255 <span class="label">Return value:</span>
256 <span class="value">New reference.</span>
257</div>
258 Returns the sequence <var>o</var> as a tuple, unless it is already a
259 tuple or list, in which case <var>o</var> is returned. Use
260 <tt class="cfunction">PySequence_Fast_GET_ITEM()</tt> to access the members of the
261 result. Returns <tt class="constant">NULL</tt> on failure. If the object is not a
262 sequence, raises <tt class="exception">TypeError</tt> with <var>m</var> as the message
263 text.
264</dd></dl>
265
266<P>
267<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"><td><nobr>PyObject*&nbsp;<b><tt id='l2h-330' xml:id='l2h-330' class="cfunction">PySequence_Fast_GET_ITEM</tt></b>(</nobr></td><td>PyObject *<var>o</var>, int <var>i</var>)</td></tr></table></dt>
268<dd>
269<div class="refcount-info">
270 <span class="label">Return value:</span>
271 <span class="value">Borrowed reference.</span>
272</div>
273 Return the <var>i</var>th element of <var>o</var>, assuming that <var>o</var> was
274 returned by <tt class="cfunction">PySequence_Fast()</tt>, <var>o</var> is not <tt class="constant">NULL</tt>,
275 and that <var>i</var> is within bounds.
276</dd></dl>
277
278<P>
279<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"><td><nobr>PyObject**&nbsp;<b><tt id='l2h-331' xml:id='l2h-331' class="cfunction">PySequence_Fast_ITEMS</tt></b>(</nobr></td><td>PyObject *<var>o</var>)</td></tr></table></dt>
280<dd>
281 Return the underlying array of PyObject pointers. Assumes that
282 <var>o</var> was returned by <tt class="cfunction">PySequence_Fast()</tt> and
283 <var>o</var> is not <tt class="constant">NULL</tt>.
284
285<span class="versionnote">New in version 2.4.</span>
286
287</dd></dl>
288
289<P>
290<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"><td><nobr>PyObject*&nbsp;<b><tt id='l2h-332' xml:id='l2h-332' class="cfunction">PySequence_ITEM</tt></b>(</nobr></td><td>PyObject *<var>o</var>, int <var>i</var>)</td></tr></table></dt>
291<dd>
292<div class="refcount-info">
293 <span class="label">Return value:</span>
294 <span class="value">New reference.</span>
295</div>
296 Return the <var>i</var>th element of <var>o</var> or <tt class="constant">NULL</tt> on failure.
297 Macro form of <tt class="cfunction">PySequence_GetItem()</tt> but without checking
298 that <tt class="cfunction">PySequence_Check(<var>o</var>)</tt> is true and without
299 adjustment for negative indices.
300
301<span class="versionnote">New in version 2.3.</span>
302
303</dd></dl>
304
305<P>
306<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"><td><nobr>int&nbsp;<b><tt id='l2h-333' xml:id='l2h-333' class="cfunction">PySequence_Fast_GET_SIZE</tt></b>(</nobr></td><td>PyObject *<var>o</var>)</td></tr></table></dt>
307<dd>
308 Returns the length of <var>o</var>, assuming that <var>o</var> was
309 returned by <tt class="cfunction">PySequence_Fast()</tt> and that <var>o</var> is
310 not <tt class="constant">NULL</tt>. The size can also be gotten by calling
311 <tt class="cfunction">PySequence_Size()</tt> on <var>o</var>, but
312 <tt class="cfunction">PySequence_Fast_GET_SIZE()</tt> is faster because it can
313 assume <var>o</var> is a list or tuple.
314</dd></dl>
315
316<P>
317
318<DIV CLASS="navigation">
319<div class='online-navigation'>
320<p></p><hr />
321<table align="center" width="100%" cellpadding="0" cellspacing="2">
322<tr>
323<td class='online-navigation'><a rel="prev" title="6.2 Number Protocol"
324 href="number.html"><img src='../icons/previous.png'
325 border='0' height='32' alt='Previous Page' width='32' /></A></td>
326<td class='online-navigation'><a rel="parent" title="6. Abstract Objects Layer"
327 href="abstract.html"><img src='../icons/up.png'
328 border='0' height='32' alt='Up One Level' width='32' /></A></td>
329<td class='online-navigation'><a rel="next" title="6.4 Mapping Protocol"
330 href="mapping.html"><img src='../icons/next.png'
331 border='0' height='32' alt='Next Page' width='32' /></A></td>
332<td align="center" width="100%">Python/C API Reference Manual</td>
333<td class='online-navigation'><a rel="contents" title="Table of Contents"
334 href="contents.html"><img src='../icons/contents.png'
335 border='0' height='32' alt='Contents' width='32' /></A></td>
336<td class='online-navigation'><img src='../icons/blank.png'
337 border='0' height='32' alt='' width='32' /></td>
338<td class='online-navigation'><a rel="index" title="Index"
339 href="genindex.html"><img src='../icons/index.png'
340 border='0' height='32' alt='Index' width='32' /></A></td>
341</tr></table>
342<div class='online-navigation'>
343<b class="navlabel">Previous:</b>
344<a class="sectref" rel="prev" href="number.html">6.2 Number Protocol</A>
345<b class="navlabel">Up:</b>
346<a class="sectref" rel="parent" href="abstract.html">6. Abstract Objects Layer</A>
347<b class="navlabel">Next:</b>
348<a class="sectref" rel="next" href="mapping.html">6.4 Mapping Protocol</A>
349</div>
350</div>
351<hr />
352<span class="release-info">Release 2.4.2, documentation updated on 28 September 2005.</span>
353</DIV>
354<!--End of Navigation Panel-->
355<ADDRESS>
356See <i><a href="about.html">About this document...</a></i> for information on suggesting changes.
357</ADDRESS>
358</BODY>
359</HTML>