Files
hustoj/web/python-docs/c-api/tuple.html
2025-03-09 17:10:56 +08:00

499 lines
35 KiB
HTML
Raw Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" lang="zh_CN">
<head>
<meta charset="utf-8" /><meta name="generator" content="Docutils 0.17.1: http://docutils.sourceforge.net/" />
<title>元组对象 &#8212; Python 3.8.20 文档</title><meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="../_static/pydoctheme.css" type="text/css" />
<link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
<script id="documentation_options" data-url_root="../" src="../_static/documentation_options.js"></script>
<script src="../_static/jquery.js"></script>
<script src="../_static/underscore.js"></script>
<script src="../_static/doctools.js"></script>
<script src="../_static/language_data.js"></script>
<script src="../_static/translations.js"></script>
<script src="../_static/sidebar.js"></script>
<link rel="search" type="application/opensearchdescription+xml"
title="在 Python 3.8.20 文档 中搜索"
href="../_static/opensearch.xml"/>
<link rel="author" title="关于这些文档" href="../about.html" />
<link rel="index" title="索引" href="../genindex.html" />
<link rel="search" title="搜索" href="../search.html" />
<link rel="copyright" title="版权所有" href="../copyright.html" />
<link rel="next" title="列表对象" href="list.html" />
<link rel="prev" title="Unicode对象和编解码器" href="unicode.html" />
<link rel="canonical" href="https://docs.python.org/3/c-api/tuple.html" />
<style>
@media only screen {
table.full-width-table {
width: 100%;
}
}
</style>
<link rel="shortcut icon" type="image/png" href="../_static/py.svg" />
<script type="text/javascript" src="../_static/copybutton.js"></script>
<script type="text/javascript" src="../_static/menu.js"></script>
</head>
<body>
<div class="mobile-nav">
<input type="checkbox" id="menuToggler" class="toggler__input" aria-controls="navigation"
aria-pressed="false" aria-expanded="false" role="button" aria-label="Menu" />
<label for="menuToggler" class="toggler__label">
<span></span>
</label>
<nav class="nav-content" role="navigation">
<a href="https://www.python.org/" class="nav-logo">
<img src="../_static/py.svg" alt="Logo"/>
</a>
<div class="version_switcher_placeholder"></div>
<form role="search" class="search" action="../search.html" method="get">
<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" class="search-icon">
<path fill-rule="nonzero"
d="M15.5 14h-.79l-.28-.27a6.5 6.5 0 001.48-5.34c-.47-2.78-2.79-5-5.59-5.34a6.505 6.505 0 00-7.27 7.27c.34 2.8 2.56 5.12 5.34 5.59a6.5 6.5 0 005.34-1.48l.27.28v.79l4.25 4.25c.41.41 1.08.41 1.49 0 .41-.41.41-1.08 0-1.49L15.5 14zm-6 0C7.01 14 5 11.99 5 9.5S7.01 5 9.5 5 14 7.01 14 9.5 11.99 14 9.5 14z" fill="#444"></path>
</svg>
<input type="text" name="q" aria-label="快速搜索"/>
<input type="submit" value="转向"/>
</form>
</nav>
<div class="menu-wrapper">
<nav class="menu" role="navigation" aria-label="main navigation">
<div class="language_switcher_placeholder"></div>
<h3><a href="../contents.html">目录</a></h3>
<ul>
<li><a class="reference internal" href="#">元组对象</a></li>
<li><a class="reference internal" href="#struct-sequence-objects">结构序列对象</a></li>
</ul>
<h4>上一个主题</h4>
<p class="topless"><a href="unicode.html"
title="上一章">Unicode对象和编解码器</a></p>
<h4>下一个主题</h4>
<p class="topless"><a href="list.html"
title="下一章">列表对象</a></p>
<div role="note" aria-label="source link">
<h3>本页</h3>
<ul class="this-page-menu">
<li><a href="../bugs.html">报告 Bug</a></li>
<li>
<a href="https://github.com/python/cpython/blob/3.8/Doc/c-api/tuple.rst"
rel="nofollow">显示源代码
</a>
</li>
</ul>
</div>
</nav>
</div>
</div>
<div id="outdated-warning" style="padding: .5em; text-align: center; background-color: #FFBABA; color: #6A0E0E;">
这个文档所针对的是一个已不再受支持的 Python 旧版本。
你应当升级版本,并阅读
<a href="/3/c-api/tuple.html"> Python 当前稳定版本的文档</a>.
</div>
<div class="related" role="navigation" aria-label="related navigation">
<h3>导航</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="../genindex.html" title="总目录"
accesskey="I">索引</a></li>
<li class="right" >
<a href="../py-modindex.html" title="Python 模块索引"
>模块</a> |</li>
<li class="right" >
<a href="list.html" title="列表对象"
accesskey="N">下一页</a> |</li>
<li class="right" >
<a href="unicode.html" title="Unicode对象和编解码器"
accesskey="P">上一页</a> |</li>
<li><img src="../_static/py.svg" alt="python logo" style="vertical-align: middle; margin-top: -1px"/></li>
<li><a href="https://www.python.org/">Python</a> &#187;</li>
<li class="switchers">
<div class="language_switcher_placeholder"></div>
<div class="version_switcher_placeholder"></div>
</li>
<li>
</li>
<li id="cpython-language-and-version">
<a href="../index.html">3.8.20 Documentation</a> &#187;
</li>
<li class="nav-item nav-item-1"><a href="index.html" >Python/C API 参考手册</a> &#187;</li>
<li class="nav-item nav-item-2"><a href="concrete.html" accesskey="U">具体的对象层</a> &#187;</li>
<li class="right">
<div class="inline-search" role="search">
<form class="inline-search" action="../search.html" method="get">
<input placeholder="快速搜索" aria-label="快速搜索" type="text" name="q" />
<input type="submit" value="转向" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
</div>
|
</li>
</ul>
</div>
<div class="document">
<div class="documentwrapper">
<div class="bodywrapper">
<div class="body" role="main">
<section id="tuple-objects">
<span id="tupleobjects"></span><h1>元组对象<a class="headerlink" href="#tuple-objects" title="永久链接至标题"></a></h1>
<span class="target" id="index-0"></span><dl class="type">
<dt id="c.PyTupleObject">
<code class="sig-name descname">PyTupleObject</code><a class="headerlink" href="#c.PyTupleObject" title="永久链接至目标"></a></dt>
<dd><p>这个 <a class="reference internal" href="structures.html#c.PyObject" title="PyObject"><code class="xref c c-type docutils literal notranslate"><span class="pre">PyObject</span></code></a> 的子类型代表一个 Python 的元组对象。</p>
</dd></dl>
<dl class="var">
<dt id="c.PyTuple_Type">
<a class="reference internal" href="type.html#c.PyTypeObject" title="PyTypeObject">PyTypeObject</a> <code class="sig-name descname">PyTuple_Type</code><a class="headerlink" href="#c.PyTuple_Type" title="永久链接至目标"></a></dt>
<dd><p><a class="reference internal" href="type.html#c.PyTypeObject" title="PyTypeObject"><code class="xref c c-type docutils literal notranslate"><span class="pre">PyTypeObject</span></code></a> 的实例代表一个 Python 元组类型,这与 Python 层面的 <a class="reference internal" href="../library/stdtypes.html#tuple" title="tuple"><code class="xref py py-class docutils literal notranslate"><span class="pre">tuple</span></code></a> 是相同的对象。</p>
</dd></dl>
<dl class="function">
<dt id="c.PyTuple_Check">
int <code class="sig-name descname">PyTuple_Check</code><span class="sig-paren">(</span><a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a><em> *p</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyTuple_Check" title="永久链接至目标"></a></dt>
<dd><p>如果 <em>p</em> 是一个元组对象或者元组类型的子类型的实例,则返回真值。</p>
</dd></dl>
<dl class="function">
<dt id="c.PyTuple_CheckExact">
int <code class="sig-name descname">PyTuple_CheckExact</code><span class="sig-paren">(</span><a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a><em> *p</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyTuple_CheckExact" title="永久链接至目标"></a></dt>
<dd><p>如果 <em>p</em> 是一个元组对象,而不是一个元组类型的子类型实例,则返回真值。</p>
</dd></dl>
<dl class="function">
<dt id="c.PyTuple_New">
<a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a>* <code class="sig-name descname">PyTuple_New</code><span class="sig-paren">(</span>Py_ssize_t<em> len</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyTuple_New" title="永久链接至目标"></a></dt>
<dd><em class="refcount">Return value: New reference.</em><p>成功时返回一个新的元组对象,长度为 <em>len</em>,失败时返回 <code class="docutils literal notranslate"><span class="pre">NULL</span></code></p>
</dd></dl>
<dl class="function">
<dt id="c.PyTuple_Pack">
<a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a>* <code class="sig-name descname">PyTuple_Pack</code><span class="sig-paren">(</span>Py_ssize_t<em> n</em>, ...<span class="sig-paren">)</span><a class="headerlink" href="#c.PyTuple_Pack" title="永久链接至目标"></a></dt>
<dd><em class="refcount">Return value: New reference.</em><p>成功时返回一个新的元组对象,大小为 <em>n</em> ,失败时返回 <code class="docutils literal notranslate"><span class="pre">NULL</span></code>。 元组值初始化为指向 Python 对象的后续 <em>n</em> 个 C 参数。 <code class="docutils literal notranslate"><span class="pre">PyTuple_Pack(2,</span> <span class="pre">a,</span> <span class="pre">b)</span></code><code class="docutils literal notranslate"><span class="pre">Py_BuildValue(&quot;(OO)&quot;,</span> <span class="pre">a,</span> <span class="pre">b)</span></code> 相等。</p>
</dd></dl>
<dl class="function">
<dt id="c.PyTuple_Size">
Py_ssize_t <code class="sig-name descname">PyTuple_Size</code><span class="sig-paren">(</span><a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a><em> *p</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyTuple_Size" title="永久链接至目标"></a></dt>
<dd><p>获取指向元组对象的指针,并返回该元组的大小。</p>
</dd></dl>
<dl class="function">
<dt id="c.PyTuple_GET_SIZE">
Py_ssize_t <code class="sig-name descname">PyTuple_GET_SIZE</code><span class="sig-paren">(</span><a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a><em> *p</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyTuple_GET_SIZE" title="永久链接至目标"></a></dt>
<dd><p>返回元组 <em>p</em> 的大小,它必须为非 <code class="docutils literal notranslate"><span class="pre">NULL</span></code> 并且指向一个元组;不执行错误检查。</p>
</dd></dl>
<dl class="function">
<dt id="c.PyTuple_GetItem">
<a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a>* <code class="sig-name descname">PyTuple_GetItem</code><span class="sig-paren">(</span><a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a><em> *p</em>, Py_ssize_t<em> pos</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyTuple_GetItem" title="永久链接至目标"></a></dt>
<dd><em class="refcount">Return value: Borrowed reference.</em><p>返回 <em>p</em> 所指向的元组中,位于 <em>pos</em> 处的对象。 如果 <em>pos</em> 超出界限,返回 <code class="docutils literal notranslate"><span class="pre">NULL</span></code>,并抛出一个 <a class="reference internal" href="../library/exceptions.html#IndexError" title="IndexError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">IndexError</span></code></a> 异常。</p>
</dd></dl>
<dl class="function">
<dt id="c.PyTuple_GET_ITEM">
<a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a>* <code class="sig-name descname">PyTuple_GET_ITEM</code><span class="sig-paren">(</span><a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a><em> *p</em>, Py_ssize_t<em> pos</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyTuple_GET_ITEM" title="永久链接至目标"></a></dt>
<dd><em class="refcount">Return value: Borrowed reference.</em><p>类似于 <a class="reference internal" href="#c.PyTuple_GetItem" title="PyTuple_GetItem"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyTuple_GetItem()</span></code></a>,但不检查其参数。</p>
</dd></dl>
<dl class="function">
<dt id="c.PyTuple_GetSlice">
<a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a>* <code class="sig-name descname">PyTuple_GetSlice</code><span class="sig-paren">(</span><a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a><em> *p</em>, Py_ssize_t<em> low</em>, Py_ssize_t<em> high</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyTuple_GetSlice" title="永久链接至目标"></a></dt>
<dd><em class="refcount">Return value: New reference.</em><p>返回 <em>p</em> 所指向的元组的切片,在 <em>low</em><em>high</em> 之间,或者在失败时返回 <code class="docutils literal notranslate"><span class="pre">NULL</span></code>。 这等同于 Python 表达式 <code class="docutils literal notranslate"><span class="pre">p[low:high]</span></code>。 不支持从列表末尾索引。</p>
</dd></dl>
<dl class="function">
<dt id="c.PyTuple_SetItem">
int <code class="sig-name descname">PyTuple_SetItem</code><span class="sig-paren">(</span><a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a><em> *p</em>, Py_ssize_t<em> pos</em>, <a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a><em> *o</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyTuple_SetItem" title="永久链接至目标"></a></dt>
<dd><p><em>p</em> 指向的元组的 <em>pos</em> 位置插入对对象 <em>o</em> 的引用。 成功时返回 <code class="docutils literal notranslate"><span class="pre">0</span></code>;如果 <em>pos</em> 越界,则返回 <code class="docutils literal notranslate"><span class="pre">-1</span></code>,并抛出一个 <a class="reference internal" href="../library/exceptions.html#IndexError" title="IndexError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">IndexError</span></code></a> 异常。</p>
<div class="admonition note">
<p class="admonition-title">注解</p>
<p>此函数会“窃取”对 <em>o</em> 的引用,并丢弃对元组中已在受影响位置的条目的引用。</p>
</div>
</dd></dl>
<dl class="function">
<dt id="c.PyTuple_SET_ITEM">
void <code class="sig-name descname">PyTuple_SET_ITEM</code><span class="sig-paren">(</span><a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a><em> *p</em>, Py_ssize_t<em> pos</em>, <a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a><em> *o</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyTuple_SET_ITEM" title="永久链接至目标"></a></dt>
<dd><p>类似于 <a class="reference internal" href="#c.PyTuple_SetItem" title="PyTuple_SetItem"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyTuple_SetItem()</span></code></a>,但不进行错误检查,并且应该 <em>只是</em> 被用来填充全新的元组。</p>
<div class="admonition note">
<p class="admonition-title">注解</p>
<p>这个宏会“偷走”一个对 <em>o</em> 的引用,但与 <a class="reference internal" href="#c.PyTuple_SetItem" title="PyTuple_SetItem"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyTuple_SetItem()</span></code></a> 不同,它 <em>不会</em> 丢弃对任何被替换项的引用;元组中位于 <em>pos</em> 位置的任何引用都将被泄漏。</p>
</div>
</dd></dl>
<dl class="function">
<dt id="c._PyTuple_Resize">
int <code class="sig-name descname">_PyTuple_Resize</code><span class="sig-paren">(</span><a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a><em> **p</em>, Py_ssize_t<em> newsize</em><span class="sig-paren">)</span><a class="headerlink" href="#c._PyTuple_Resize" title="永久链接至目标"></a></dt>
<dd><p>可以用于调整元组的大小。 <em>newsize</em> 将是元组的新长度。 因为元组 <em>被认为</em> 是不可变的,所以只有在对象仅有一个引用时,才应该使用它。 如果元组已经被代码的其他部分所引用,请不要使用此项。 元组在最后总是会增长或缩小。 把它看作是销毁旧元组并创建一个新元组,只会更有效。 成功时返回 <code class="docutils literal notranslate"><span class="pre">0</span></code> 。 客户端代码不应假定 <code class="docutils literal notranslate"><span class="pre">*p</span></code> 的结果值将与调用此函数之前的值相同。 如果替换了 <code class="docutils literal notranslate"><span class="pre">*p</span></code> 引用的对象,则原始的 <code class="docutils literal notranslate"><span class="pre">*p</span></code> 将被销毁。 失败时,返回 <code class="docutils literal notranslate"><span class="pre">-1</span></code>,将 <code class="docutils literal notranslate"><span class="pre">*p</span></code> 设置为 <code class="docutils literal notranslate"><span class="pre">NULL</span></code>,并引发 <a class="reference internal" href="../library/exceptions.html#MemoryError" title="MemoryError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">MemoryError</span></code></a> 或者 <a class="reference internal" href="../library/exceptions.html#SystemError" title="SystemError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">SystemError</span></code></a></p>
</dd></dl>
<dl class="function">
<dt id="c.PyTuple_ClearFreeList">
int <code class="sig-name descname">PyTuple_ClearFreeList</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#c.PyTuple_ClearFreeList" title="永久链接至目标"></a></dt>
<dd><p>清空释放列表。 返回所释放的条目数。</p>
</dd></dl>
</section>
<section id="struct-sequence-objects">
<h1>结构序列对象<a class="headerlink" href="#struct-sequence-objects" title="永久链接至标题"></a></h1>
<p>结构序列对象是等价于 <a class="reference internal" href="../library/collections.html#collections.namedtuple" title="collections.namedtuple"><code class="xref py py-func docutils literal notranslate"><span class="pre">namedtuple()</span></code></a> 的 C 对象,即一个序列,其中的条目也可以通过属性访问。 要创建结构序列,你首先必须创建特定的结构序列类型。</p>
<dl class="function">
<dt id="c.PyStructSequence_NewType">
<a class="reference internal" href="type.html#c.PyTypeObject" title="PyTypeObject">PyTypeObject</a>* <code class="sig-name descname">PyStructSequence_NewType</code><span class="sig-paren">(</span><a class="reference internal" href="#c.PyStructSequence_Desc" title="PyStructSequence_Desc">PyStructSequence_Desc</a><em> *desc</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyStructSequence_NewType" title="永久链接至目标"></a></dt>
<dd><em class="refcount">Return value: New reference.</em><p>根据 <em>desc</em> 中的数据创建一个新的结构序列类型,如下所述。 可以使用 <a class="reference internal" href="#c.PyStructSequence_New" title="PyStructSequence_New"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyStructSequence_New()</span></code></a> 创建结果类型的实例。</p>
</dd></dl>
<dl class="function">
<dt id="c.PyStructSequence_InitType">
void <code class="sig-name descname">PyStructSequence_InitType</code><span class="sig-paren">(</span><a class="reference internal" href="type.html#c.PyTypeObject" title="PyTypeObject">PyTypeObject</a><em> *type</em>, <a class="reference internal" href="#c.PyStructSequence_Desc" title="PyStructSequence_Desc">PyStructSequence_Desc</a><em> *desc</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyStructSequence_InitType" title="永久链接至目标"></a></dt>
<dd><p><em>desc</em> 就地初始化结构序列类型 <em>type</em></p>
</dd></dl>
<dl class="function">
<dt id="c.PyStructSequence_InitType2">
int <code class="sig-name descname">PyStructSequence_InitType2</code><span class="sig-paren">(</span><a class="reference internal" href="type.html#c.PyTypeObject" title="PyTypeObject">PyTypeObject</a><em> *type</em>, <a class="reference internal" href="#c.PyStructSequence_Desc" title="PyStructSequence_Desc">PyStructSequence_Desc</a><em> *desc</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyStructSequence_InitType2" title="永久链接至目标"></a></dt>
<dd><p><code class="docutils literal notranslate"><span class="pre">PyStructSequence_InitType</span></code> 相同,但成功时返回 <code class="docutils literal notranslate"><span class="pre">0</span></code> ,失败时返回 <code class="docutils literal notranslate"><span class="pre">-1</span></code></p>
<div class="versionadded">
<p><span class="versionmodified added">3.4 新版功能.</span></p>
</div>
</dd></dl>
<dl class="type">
<dt id="c.PyStructSequence_Desc">
<code class="sig-name descname">PyStructSequence_Desc</code><a class="headerlink" href="#c.PyStructSequence_Desc" title="永久链接至目标"></a></dt>
<dd><p>包含要创建的结构序列类型的元信息。</p>
<table class="docutils align-default">
<colgroup>
<col style="width: 22%" />
<col style="width: 34%" />
<col style="width: 44%" />
</colgroup>
<thead>
<tr class="row-odd"><th class="head"><p></p></th>
<th class="head"><p>C 类型</p></th>
<th class="head"><p>含意</p></th>
</tr>
</thead>
<tbody>
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">name</span></code></p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">const</span> <span class="pre">char</span> <span class="pre">*</span></code></p></td>
<td><p>结构序列类型的名称</p></td>
</tr>
<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">doc</span></code></p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">const</span> <span class="pre">char</span> <span class="pre">*</span></code></p></td>
<td><p>指向要忽略类型的文档字符串或 <code class="docutils literal notranslate"><span class="pre">NULL</span></code> 的指针</p></td>
</tr>
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">fields</span></code></p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">PyStructSequence_Field</span> <span class="pre">*</span></code></p></td>
<td><p>指向以 <code class="docutils literal notranslate"><span class="pre">NULL</span></code> 结尾的数组的指针,其字段名称为新类型</p></td>
</tr>
<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">n_in_sequence</span></code></p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">int</span></code></p></td>
<td><p>Python侧可见的字段数如果用作元组</p></td>
</tr>
</tbody>
</table>
</dd></dl>
<dl class="type">
<dt id="c.PyStructSequence_Field">
<code class="sig-name descname">PyStructSequence_Field</code><a class="headerlink" href="#c.PyStructSequence_Field" title="永久链接至目标"></a></dt>
<dd><p>描述结构序列的一个字段。 当结构序列被建模为元组时,所有字段的类型都是 <a class="reference internal" href="structures.html#c.PyObject" title="PyObject"><code class="xref c c-type docutils literal notranslate"><span class="pre">PyObject*</span></code></a>。 在 <a class="reference internal" href="#c.PyStructSequence_Desc" title="PyStructSequence_Desc"><code class="xref c c-type docutils literal notranslate"><span class="pre">PyStructSequence_Desc</span></code></a><code class="xref py py-attr docutils literal notranslate"><span class="pre">fields</span></code> 数组中的索引确定了结构序列描述的是哪个字段。</p>
<table class="docutils align-default">
<colgroup>
<col style="width: 16%" />
<col style="width: 26%" />
<col style="width: 59%" />
</colgroup>
<thead>
<tr class="row-odd"><th class="head"><p></p></th>
<th class="head"><p>C 类型</p></th>
<th class="head"><p>含意</p></th>
</tr>
</thead>
<tbody>
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">name</span></code></p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">const</span> <span class="pre">char</span> <span class="pre">*</span></code></p></td>
<td><p>字段的名称或 <code class="docutils literal notranslate"><span class="pre">NULL</span></code> ,若要结束命名字段的列表,请设置为 <a class="reference internal" href="#c.PyStructSequence_UnnamedField" title="PyStructSequence_UnnamedField"><code class="xref c c-data docutils literal notranslate"><span class="pre">PyStructSequence_UnnamedField</span></code></a> 以保留未命名字段</p></td>
</tr>
<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">doc</span></code></p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">const</span> <span class="pre">char</span> <span class="pre">*</span></code></p></td>
<td><p>要忽略的字段文档字符串或 <code class="docutils literal notranslate"><span class="pre">NULL</span></code></p></td>
</tr>
</tbody>
</table>
</dd></dl>
<dl class="var">
<dt id="c.PyStructSequence_UnnamedField">
char* <code class="sig-name descname">PyStructSequence_UnnamedField</code><a class="headerlink" href="#c.PyStructSequence_UnnamedField" title="永久链接至目标"></a></dt>
<dd><p>字段名的特殊值将保持未命名状态。</p>
</dd></dl>
<dl class="function">
<dt id="c.PyStructSequence_New">
<a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a>* <code class="sig-name descname">PyStructSequence_New</code><span class="sig-paren">(</span><a class="reference internal" href="type.html#c.PyTypeObject" title="PyTypeObject">PyTypeObject</a><em> *type</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyStructSequence_New" title="永久链接至目标"></a></dt>
<dd><em class="refcount">Return value: New reference.</em><p>创建 <em>type</em> 的实例,该实例必须使用 <a class="reference internal" href="#c.PyStructSequence_NewType" title="PyStructSequence_NewType"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyStructSequence_NewType()</span></code></a> 创建。</p>
</dd></dl>
<dl class="function">
<dt id="c.PyStructSequence_GetItem">
<a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a>* <code class="sig-name descname">PyStructSequence_GetItem</code><span class="sig-paren">(</span><a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a><em> *p</em>, Py_ssize_t<em> pos</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyStructSequence_GetItem" title="永久链接至目标"></a></dt>
<dd><em class="refcount">Return value: Borrowed reference.</em><p>返回 <em>p</em> 所指向的结构序列中,位于 <em>pos</em> 处的对象。不需要进行边界检查。</p>
</dd></dl>
<dl class="function">
<dt id="c.PyStructSequence_GET_ITEM">
<a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a>* <code class="sig-name descname">PyStructSequence_GET_ITEM</code><span class="sig-paren">(</span><a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a><em> *p</em>, Py_ssize_t<em> pos</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyStructSequence_GET_ITEM" title="永久链接至目标"></a></dt>
<dd><em class="refcount">Return value: Borrowed reference.</em><p><a class="reference internal" href="#c.PyStructSequence_GetItem" title="PyStructSequence_GetItem"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyStructSequence_GetItem()</span></code></a> 的宏版本。</p>
</dd></dl>
<dl class="function">
<dt id="c.PyStructSequence_SetItem">
void <code class="sig-name descname">PyStructSequence_SetItem</code><span class="sig-paren">(</span><a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a><em> *p</em>, Py_ssize_t<em> pos</em>, <a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a><em> *o</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyStructSequence_SetItem" title="永久链接至目标"></a></dt>
<dd><p>将结构序列 <em>p</em> 的索引 <em>pos</em> 处的字段设置为值 <em>o</em>。 与 <a class="reference internal" href="#c.PyTuple_SET_ITEM" title="PyTuple_SET_ITEM"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyTuple_SET_ITEM()</span></code></a> 一样,它应该只用于填充全新的实例。</p>
<div class="admonition note">
<p class="admonition-title">注解</p>
<p>这个函数“窃取”了指向 <em>o</em> 的一个引用。</p>
</div>
</dd></dl>
<dl class="function">
<dt id="c.PyStructSequence_SET_ITEM">
void <code class="sig-name descname">PyStructSequence_SET_ITEM</code><span class="sig-paren">(</span><a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a><em> *p</em>, Py_ssize_t<em> *pos</em>, <a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a><em> *o</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyStructSequence_SET_ITEM" title="永久链接至目标"></a></dt>
<dd><p><a class="reference internal" href="#c.PyStructSequence_SetItem" title="PyStructSequence_SetItem"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyStructSequence_SetItem()</span></code></a> 的宏版本。</p>
<div class="admonition note">
<p class="admonition-title">注解</p>
<p>这个函数“窃取”了指向 <em>o</em> 的一个引用。</p>
</div>
</dd></dl>
</section>
</div>
</div>
</div>
<div class="sphinxsidebar" role="navigation" aria-label="main navigation">
<div class="sphinxsidebarwrapper">
<h3><a href="../contents.html">目录</a></h3>
<ul>
<li><a class="reference internal" href="#">元组对象</a></li>
<li><a class="reference internal" href="#struct-sequence-objects">结构序列对象</a></li>
</ul>
<h4>上一个主题</h4>
<p class="topless"><a href="unicode.html"
title="上一章">Unicode对象和编解码器</a></p>
<h4>下一个主题</h4>
<p class="topless"><a href="list.html"
title="下一章">列表对象</a></p>
<div role="note" aria-label="source link">
<h3>本页</h3>
<ul class="this-page-menu">
<li><a href="../bugs.html">报告 Bug</a></li>
<li>
<a href="https://github.com/python/cpython/blob/3.8/Doc/c-api/tuple.rst"
rel="nofollow">显示源代码
</a>
</li>
</ul>
</div>
</div>
</div>
<div class="clearer"></div>
</div>
<div class="related" role="navigation" aria-label="related navigation">
<h3>导航</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="../genindex.html" title="总目录"
>索引</a></li>
<li class="right" >
<a href="../py-modindex.html" title="Python 模块索引"
>模块</a> |</li>
<li class="right" >
<a href="list.html" title="列表对象"
>下一页</a> |</li>
<li class="right" >
<a href="unicode.html" title="Unicode对象和编解码器"
>上一页</a> |</li>
<li><img src="../_static/py.svg" alt="python logo" style="vertical-align: middle; margin-top: -1px"/></li>
<li><a href="https://www.python.org/">Python</a> &#187;</li>
<li class="switchers">
<div class="language_switcher_placeholder"></div>
<div class="version_switcher_placeholder"></div>
</li>
<li>
</li>
<li id="cpython-language-and-version">
<a href="../index.html">3.8.20 Documentation</a> &#187;
</li>
<li class="nav-item nav-item-1"><a href="index.html" >Python/C API 参考手册</a> &#187;</li>
<li class="nav-item nav-item-2"><a href="concrete.html" >具体的对象层</a> &#187;</li>
<li class="right">
<div class="inline-search" role="search">
<form class="inline-search" action="../search.html" method="get">
<input placeholder="快速搜索" aria-label="快速搜索" type="text" name="q" />
<input type="submit" value="转向" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
</div>
|
</li>
</ul>
</div>
<div class="footer">
&copy; <a href="../copyright.html">版权所有</a> 2001-2024, Python Software Foundation.
<br />
This page is licensed under the Python Software Foundation License Version 2.
<br />
Examples, recipes, and other code in the documentation are additionally licensed under the Zero Clause BSD License.
<br />
<br />
The Python Software Foundation is a non-profit corporation.
<a href="https://www.python.org/psf/donations/">Please donate.</a>
<br />
<br />
最后更新于 12月 09, 2024.
<a href="https://docs.python.org/3/bugs.html">Found a bug</a>?
<br />
Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 2.4.4.
</div>
</body>
</html>