PageRenderTime 103ms CodeModel.GetById 8ms RepoModel.GetById 1ms app.codeStats 0ms

/html/c-api/list.html

https://bitbucket.org/andrikmb/py3k-doc
HTML | 272 lines | 244 code | 28 blank | 0 comment | 0 complexity | 93d9051f23a5b6df7722643f6b45ad14 MD5 | raw file
Possible License(s): BSD-3-Clause
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  2. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  3. <html xmlns="http://www.w3.org/1999/xhtml">
  4. <head>
  5. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  6. <title>List Objects &mdash; Documentação Python v3.1c1</title>
  7. <link rel="stylesheet" href="../_static/default.css" type="text/css" />
  8. <link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
  9. <script type="text/javascript">
  10. var DOCUMENTATION_OPTIONS = {
  11. URL_ROOT: '../',
  12. VERSION: '3.1c1',
  13. COLLAPSE_MODINDEX: false,
  14. FILE_SUFFIX: '.html',
  15. HAS_SOURCE: true
  16. };
  17. </script>
  18. <script type="text/javascript" src="../_static/jquery.js"></script>
  19. <script type="text/javascript" src="../_static/doctools.js"></script>
  20. <link rel="search" type="application/opensearchdescription+xml"
  21. title="Search within Documentação Python v3.1c1"
  22. href="../_static/opensearch.xml"/>
  23. <link rel="author" title="About these documents" href="../about.html" />
  24. <link rel="copyright" title="Copyright" href="../copyright.html" />
  25. <link rel="top" title="Documentação Python v3.1c1" href="../index.html" />
  26. <link rel="up" title="Concrete Objects Layer" href="concrete.html" />
  27. <link rel="next" title="Dictionary Objects" href="dict.html" />
  28. <link rel="prev" title="Tuple Objects" href="tuple.html" />
  29. <link rel="shortcut icon" type="image/png" href="../_static/py.png" />
  30. </head>
  31. <body>
  32. <div class="related">
  33. <h3>Navigation</h3>
  34. <ul>
  35. <li class="right" style="margin-right: 10px">
  36. <a href="../genindex.html" title="Índice Geral"
  37. accesskey="I">&iacute;ndice</a></li>
  38. <li class="right" >
  39. <a href="../modindex.html" title="Índice Global de Móodulos"
  40. accesskey="M">m&oacute;dulos</a> |</li>
  41. <li class="right" >
  42. <a href="dict.html" title="Dictionary Objects"
  43. accesskey="N">pr&oacute;ximo</a> |</li>
  44. <li class="right" >
  45. <a href="tuple.html" title="Tuple Objects"
  46. accesskey="P">anterior</a> |</li>
  47. <li><img src="../_static/py.png" alt=""
  48. style="vertical-align: middle; margin-top: -1px"/></li>
  49. <li><a href="../index.html">Documentação Python v3.1c1</a> &raquo;</li>
  50. <li><a href="index.html" >Python/C API Reference Manual</a> &raquo;</li>
  51. <li><a href="concrete.html" accesskey="U">Concrete Objects Layer</a> &raquo;</li>
  52. </ul>
  53. </div>
  54. <div class="document">
  55. <div class="documentwrapper">
  56. <div class="bodywrapper">
  57. <div class="body">
  58. <div class="section" id="list-objects">
  59. <span id="listobjects"></span><h1>List Objects<a class="headerlink" href="#list-objects" title="Permalink to this headline"></a></h1>
  60. <span class="target" id="index-85"></span><dl class="ctype">
  61. <dt id="PyListObject">
  62. <tt class="descname">PyListObject</tt><a class="headerlink" href="#PyListObject" title="Link permanente para esta defini&ccedil;&atilde;o"></a></dt>
  63. <dd>This subtype of <a title="PyObject" class="reference external" href="structures.html#PyObject"><tt class="xref docutils literal"><span class="pre">PyObject</span></tt></a> represents a Python list object.</dd></dl>
  64. <dl class="cvar">
  65. <dt id="PyList_Type">
  66. <a title="PyTypeObject" class="reference external" href="type.html#PyTypeObject">PyTypeObject</a> <tt class="descname">PyList_Type</tt><a class="headerlink" href="#PyList_Type" title="Link permanente para esta defini&ccedil;&atilde;o"></a></dt>
  67. <dd><p id="index-86">This instance of <a title="PyTypeObject" class="reference external" href="type.html#PyTypeObject"><tt class="xref docutils literal"><span class="pre">PyTypeObject</span></tt></a> represents the Python list type.
  68. This is the same object as <tt class="docutils literal"><span class="pre">list</span></tt> and <tt class="docutils literal"><span class="pre">types.ListType</span></tt> in the Python
  69. layer.</p>
  70. </dd></dl>
  71. <dl class="cfunction">
  72. <dt id="PyList_Check">
  73. int <tt class="descname">PyList_Check</tt><big>(</big><a title="PyObject" class="reference external" href="structures.html#PyObject">PyObject</a><em> *p</em><big>)</big><a class="headerlink" href="#PyList_Check" title="Link permanente para esta defini&ccedil;&atilde;o"></a></dt>
  74. <dd>Return true if <em>p</em> is a list object or an instance of a subtype of the list
  75. type.</dd></dl>
  76. <dl class="cfunction">
  77. <dt id="PyList_CheckExact">
  78. int <tt class="descname">PyList_CheckExact</tt><big>(</big><a title="PyObject" class="reference external" href="structures.html#PyObject">PyObject</a><em> *p</em><big>)</big><a class="headerlink" href="#PyList_CheckExact" title="Link permanente para esta defini&ccedil;&atilde;o"></a></dt>
  79. <dd>Return true if <em>p</em> is a list object, but not an instance of a subtype of
  80. the list type.</dd></dl>
  81. <dl class="cfunction">
  82. <dt id="PyList_New">
  83. <a title="PyObject" class="reference external" href="structures.html#PyObject">PyObject</a>* <tt class="descname">PyList_New</tt><big>(</big>Py_ssize_t<em> len</em><big>)</big><a class="headerlink" href="#PyList_New" title="Link permanente para esta defini&ccedil;&atilde;o"></a></dt>
  84. <dd><em class="refcount">Return value: New reference.</em><p>Return a new list of length <em>len</em> on success, or <em>NULL</em> on failure.</p>
  85. <div class="admonition note">
  86. <p class="first admonition-title">Note</p>
  87. <p class="last">If <em>length</em> is greater than zero, the returned list object&#8217;s items are
  88. set to <tt class="docutils literal"><span class="pre">NULL</span></tt>. Thus you cannot use abstract API functions such as
  89. <a title="PySequence_SetItem" class="reference external" href="sequence.html#PySequence_SetItem"><tt class="xref docutils literal"><span class="pre">PySequence_SetItem</span></tt></a> or expose the object to Python code before
  90. setting all items to a real object with <a title="PyList_SetItem" class="reference internal" href="#PyList_SetItem"><tt class="xref docutils literal"><span class="pre">PyList_SetItem</span></tt></a>.</p>
  91. </div>
  92. </dd></dl>
  93. <dl class="cfunction">
  94. <dt id="PyList_Size">
  95. Py_ssize_t <tt class="descname">PyList_Size</tt><big>(</big><a title="PyObject" class="reference external" href="structures.html#PyObject">PyObject</a><em> *list</em><big>)</big><a class="headerlink" href="#PyList_Size" title="Link permanente para esta defini&ccedil;&atilde;o"></a></dt>
  96. <dd><p id="index-87">Return the length of the list object in <em>list</em>; this is equivalent to
  97. <tt class="docutils literal"><span class="pre">len(list)</span></tt> on a list object.</p>
  98. </dd></dl>
  99. <dl class="cfunction">
  100. <dt id="PyList_GET_SIZE">
  101. Py_ssize_t <tt class="descname">PyList_GET_SIZE</tt><big>(</big><a title="PyObject" class="reference external" href="structures.html#PyObject">PyObject</a><em> *list</em><big>)</big><a class="headerlink" href="#PyList_GET_SIZE" title="Link permanente para esta defini&ccedil;&atilde;o"></a></dt>
  102. <dd>Macro form of <a title="PyList_Size" class="reference internal" href="#PyList_Size"><tt class="xref docutils literal"><span class="pre">PyList_Size</span></tt></a> without error checking.</dd></dl>
  103. <dl class="cfunction">
  104. <dt id="PyList_GetItem">
  105. <a title="PyObject" class="reference external" href="structures.html#PyObject">PyObject</a>* <tt class="descname">PyList_GetItem</tt><big>(</big><a title="PyObject" class="reference external" href="structures.html#PyObject">PyObject</a><em> *list</em>, Py_ssize_t<em> index</em><big>)</big><a class="headerlink" href="#PyList_GetItem" title="Link permanente para esta defini&ccedil;&atilde;o"></a></dt>
  106. <dd><em class="refcount">Return value: Borrowed reference.</em><p>Return the object at position <em>pos</em> in the list pointed to by <em>p</em>. The
  107. position must be positive, indexing from the end of the list is not
  108. supported. If <em>pos</em> is out of bounds, return <em>NULL</em> and set an
  109. <a title="exceptions.IndexError" class="reference external" href="../library/exceptions.html#exceptions.IndexError"><tt class="xref docutils literal"><span class="pre">IndexError</span></tt></a> exception.</p>
  110. </dd></dl>
  111. <dl class="cfunction">
  112. <dt id="PyList_GET_ITEM">
  113. <a title="PyObject" class="reference external" href="structures.html#PyObject">PyObject</a>* <tt class="descname">PyList_GET_ITEM</tt><big>(</big><a title="PyObject" class="reference external" href="structures.html#PyObject">PyObject</a><em> *list</em>, Py_ssize_t<em> i</em><big>)</big><a class="headerlink" href="#PyList_GET_ITEM" title="Link permanente para esta defini&ccedil;&atilde;o"></a></dt>
  114. <dd><em class="refcount">Return value: Borrowed reference.</em><p>Macro form of <a title="PyList_GetItem" class="reference internal" href="#PyList_GetItem"><tt class="xref docutils literal"><span class="pre">PyList_GetItem</span></tt></a> without error checking.</p>
  115. </dd></dl>
  116. <dl class="cfunction">
  117. <dt id="PyList_SetItem">
  118. int <tt class="descname">PyList_SetItem</tt><big>(</big><a title="PyObject" class="reference external" href="structures.html#PyObject">PyObject</a><em> *list</em>, Py_ssize_t<em> index</em>, <a title="PyObject" class="reference external" href="structures.html#PyObject">PyObject</a><em> *item</em><big>)</big><a class="headerlink" href="#PyList_SetItem" title="Link permanente para esta defini&ccedil;&atilde;o"></a></dt>
  119. <dd><p>Set the item at index <em>index</em> in list to <em>item</em>. Return <tt class="docutils literal"><span class="pre">0</span></tt> on success
  120. or <tt class="docutils literal"><span class="pre">-1</span></tt> on failure.</p>
  121. <div class="admonition note">
  122. <p class="first admonition-title">Note</p>
  123. <p class="last">This function &#8220;steals&#8221; a reference to <em>item</em> and discards a reference to
  124. an item already in the list at the affected position.</p>
  125. </div>
  126. </dd></dl>
  127. <dl class="cfunction">
  128. <dt id="PyList_SET_ITEM">
  129. void <tt class="descname">PyList_SET_ITEM</tt><big>(</big><a title="PyObject" class="reference external" href="structures.html#PyObject">PyObject</a><em> *list</em>, Py_ssize_t<em> i</em>, <a title="PyObject" class="reference external" href="structures.html#PyObject">PyObject</a><em> *o</em><big>)</big><a class="headerlink" href="#PyList_SET_ITEM" title="Link permanente para esta defini&ccedil;&atilde;o"></a></dt>
  130. <dd><p>Macro form of <a title="PyList_SetItem" class="reference internal" href="#PyList_SetItem"><tt class="xref docutils literal"><span class="pre">PyList_SetItem</span></tt></a> without error checking. This is
  131. normally only used to fill in new lists where there is no previous content.</p>
  132. <div class="admonition note">
  133. <p class="first admonition-title">Note</p>
  134. <p class="last">This macro &#8220;steals&#8221; a reference to <em>item</em>, and, unlike
  135. <a title="PyList_SetItem" class="reference internal" href="#PyList_SetItem"><tt class="xref docutils literal"><span class="pre">PyList_SetItem</span></tt></a>, does <em>not</em> discard a reference to any item that
  136. is being replaced; any reference in <em>list</em> at position <em>i</em> will be
  137. leaked.</p>
  138. </div>
  139. </dd></dl>
  140. <dl class="cfunction">
  141. <dt id="PyList_Insert">
  142. int <tt class="descname">PyList_Insert</tt><big>(</big><a title="PyObject" class="reference external" href="structures.html#PyObject">PyObject</a><em> *list</em>, Py_ssize_t<em> index</em>, <a title="PyObject" class="reference external" href="structures.html#PyObject">PyObject</a><em> *item</em><big>)</big><a class="headerlink" href="#PyList_Insert" title="Link permanente para esta defini&ccedil;&atilde;o"></a></dt>
  143. <dd>Insert the item <em>item</em> into list <em>list</em> in front of index <em>index</em>. Return
  144. <tt class="docutils literal"><span class="pre">0</span></tt> if successful; return <tt class="docutils literal"><span class="pre">-1</span></tt> and set an exception if unsuccessful.
  145. Analogous to <tt class="docutils literal"><span class="pre">list.insert(index,</span> <span class="pre">item)</span></tt>.</dd></dl>
  146. <dl class="cfunction">
  147. <dt id="PyList_Append">
  148. int <tt class="descname">PyList_Append</tt><big>(</big><a title="PyObject" class="reference external" href="structures.html#PyObject">PyObject</a><em> *list</em>, <a title="PyObject" class="reference external" href="structures.html#PyObject">PyObject</a><em> *item</em><big>)</big><a class="headerlink" href="#PyList_Append" title="Link permanente para esta defini&ccedil;&atilde;o"></a></dt>
  149. <dd>Append the object <em>item</em> at the end of list <em>list</em>. Return <tt class="docutils literal"><span class="pre">0</span></tt> if
  150. successful; return <tt class="docutils literal"><span class="pre">-1</span></tt> and set an exception if unsuccessful. Analogous
  151. to <tt class="docutils literal"><span class="pre">list.append(item)</span></tt>.</dd></dl>
  152. <dl class="cfunction">
  153. <dt id="PyList_GetSlice">
  154. <a title="PyObject" class="reference external" href="structures.html#PyObject">PyObject</a>* <tt class="descname">PyList_GetSlice</tt><big>(</big><a title="PyObject" class="reference external" href="structures.html#PyObject">PyObject</a><em> *list</em>, Py_ssize_t<em> low</em>, Py_ssize_t<em> high</em><big>)</big><a class="headerlink" href="#PyList_GetSlice" title="Link permanente para esta defini&ccedil;&atilde;o"></a></dt>
  155. <dd><em class="refcount">Return value: New reference.</em><p>Return a list of the objects in <em>list</em> containing the objects <em>between</em>
  156. <em>low</em> and <em>high</em>. Return <em>NULL</em> and set an exception if unsuccessful.
  157. Analogous to <tt class="docutils literal"><span class="pre">list[low:high]</span></tt>.</p>
  158. </dd></dl>
  159. <dl class="cfunction">
  160. <dt id="PyList_SetSlice">
  161. int <tt class="descname">PyList_SetSlice</tt><big>(</big><a title="PyObject" class="reference external" href="structures.html#PyObject">PyObject</a><em> *list</em>, Py_ssize_t<em> low</em>, Py_ssize_t<em> high</em>, <a title="PyObject" class="reference external" href="structures.html#PyObject">PyObject</a><em> *itemlist</em><big>)</big><a class="headerlink" href="#PyList_SetSlice" title="Link permanente para esta defini&ccedil;&atilde;o"></a></dt>
  162. <dd>Set the slice of <em>list</em> between <em>low</em> and <em>high</em> to the contents of
  163. <em>itemlist</em>. Analogous to <tt class="docutils literal"><span class="pre">list[low:high]</span> <span class="pre">=</span> <span class="pre">itemlist</span></tt>. The <em>itemlist</em> may
  164. be <em>NULL</em>, indicating the assignment of an empty list (slice deletion).
  165. Return <tt class="docutils literal"><span class="pre">0</span></tt> on success, <tt class="docutils literal"><span class="pre">-1</span></tt> on failure.</dd></dl>
  166. <dl class="cfunction">
  167. <dt id="PyList_Sort">
  168. int <tt class="descname">PyList_Sort</tt><big>(</big><a title="PyObject" class="reference external" href="structures.html#PyObject">PyObject</a><em> *list</em><big>)</big><a class="headerlink" href="#PyList_Sort" title="Link permanente para esta defini&ccedil;&atilde;o"></a></dt>
  169. <dd>Sort the items of <em>list</em> in place. Return <tt class="docutils literal"><span class="pre">0</span></tt> on success, <tt class="docutils literal"><span class="pre">-1</span></tt> on
  170. failure. This is equivalent to <tt class="docutils literal"><span class="pre">list.sort()</span></tt>.</dd></dl>
  171. <dl class="cfunction">
  172. <dt id="PyList_Reverse">
  173. int <tt class="descname">PyList_Reverse</tt><big>(</big><a title="PyObject" class="reference external" href="structures.html#PyObject">PyObject</a><em> *list</em><big>)</big><a class="headerlink" href="#PyList_Reverse" title="Link permanente para esta defini&ccedil;&atilde;o"></a></dt>
  174. <dd>Reverse the items of <em>list</em> in place. Return <tt class="docutils literal"><span class="pre">0</span></tt> on success, <tt class="docutils literal"><span class="pre">-1</span></tt> on
  175. failure. This is the equivalent of <tt class="docutils literal"><span class="pre">list.reverse()</span></tt>.</dd></dl>
  176. <dl class="cfunction">
  177. <dt id="PyList_AsTuple">
  178. <a title="PyObject" class="reference external" href="structures.html#PyObject">PyObject</a>* <tt class="descname">PyList_AsTuple</tt><big>(</big><a title="PyObject" class="reference external" href="structures.html#PyObject">PyObject</a><em> *list</em><big>)</big><a class="headerlink" href="#PyList_AsTuple" title="Link permanente para esta defini&ccedil;&atilde;o"></a></dt>
  179. <dd><em class="refcount">Return value: New reference.</em><p id="index-88">Return a new tuple object containing the contents of <em>list</em>; equivalent to
  180. <tt class="docutils literal"><span class="pre">tuple(list)</span></tt>.</p>
  181. </dd></dl>
  182. </div>
  183. </div>
  184. </div>
  185. </div>
  186. <div class="sphinxsidebar">
  187. <div class="sphinxsidebarwrapper">
  188. <h4>T&oacute;pico anterior</h4>
  189. <p class="topless"><a href="tuple.html"
  190. title="cap&iacute;tulo anterior">Tuple Objects</a></p>
  191. <h4>Pr&oacute;ximo t&oacute;pico</h4>
  192. <p class="topless"><a href="dict.html"
  193. title="pr&oacute;ximo cap&iacute;tulo">Dictionary Objects</a></p>
  194. <h3>Esta p&aacute;gina</h3>
  195. <ul class="this-page-menu">
  196. <li><a href="../_sources/c-api/list.txt"
  197. rel="nofollow">Mostrar fonte</a></li>
  198. </ul>
  199. <div id="searchbox" style="display: none">
  200. <h3>Busca r&aacute;pida</h3>
  201. <form class="search" action="../search.html" method="get">
  202. <input type="text" name="q" size="18" />
  203. <input type="submit" value="Ir" />
  204. <input type="hidden" name="check_keywords" value="yes" />
  205. <input type="hidden" name="area" value="default" />
  206. </form>
  207. <p class="searchtip" style="font-size: 90%">
  208. Informe o termo, m&oacute;dulo, classe ou nome de fun&ccedil;&atilde;o para buscar.
  209. </p>
  210. </div>
  211. <script type="text/javascript">$('#searchbox').show(0);</script>
  212. </div>
  213. </div>
  214. <div class="clearer"></div>
  215. </div>
  216. <div class="related">
  217. <h3>Navigation</h3>
  218. <ul>
  219. <li class="right" style="margin-right: 10px">
  220. <a href="../genindex.html" title="Índice Geral"
  221. >&iacute;ndice</a></li>
  222. <li class="right" >
  223. <a href="../modindex.html" title="Índice Global de Móodulos"
  224. >m&oacute;dulos</a> |</li>
  225. <li class="right" >
  226. <a href="dict.html" title="Dictionary Objects"
  227. >pr&oacute;ximo</a> |</li>
  228. <li class="right" >
  229. <a href="tuple.html" title="Tuple Objects"
  230. >anterior</a> |</li>
  231. <li><img src="../_static/py.png" alt=""
  232. style="vertical-align: middle; margin-top: -1px"/></li>
  233. <li><a href="../index.html">Documentação Python v3.1c1</a> &raquo;</li>
  234. <li><a href="index.html" >Python/C API Reference Manual</a> &raquo;</li>
  235. <li><a href="concrete.html" >Concrete Objects Layer</a> &raquo;</li>
  236. </ul>
  237. </div>
  238. <div class="footer">
  239. &copy; <a href="../copyright.html">Copyright</a> 1990-2009, Python Software Foundation.
  240. Atualizado em Jun 28, 2009.
  241. Criado usando <a href="http://sphinx.pocoo.org/">Sphinx</a> 0.6.1.
  242. </div>
  243. </body>
  244. </html>