增加python文档
This commit is contained in:
431
web/python-docs/c-api/bytes.html
Normal file
431
web/python-docs/c-api/bytes.html
Normal file
@@ -0,0 +1,431 @@
|
||||
|
||||
<!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>bytes 对象 — 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="bytearray.html" />
|
||||
<link rel="prev" title="复数对象" href="complex.html" />
|
||||
<link rel="canonical" href="https://docs.python.org/3/c-api/bytes.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>
|
||||
<h4>上一个主题</h4>
|
||||
<p class="topless"><a href="complex.html"
|
||||
title="上一章">复数对象</a></p>
|
||||
<h4>下一个主题</h4>
|
||||
<p class="topless"><a href="bytearray.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/bytes.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/bytes.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="bytearray.html" title="字节数组对象"
|
||||
accesskey="N">下一页</a> |</li>
|
||||
<li class="right" >
|
||||
<a href="complex.html" title="复数对象"
|
||||
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> »</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> »
|
||||
</li>
|
||||
|
||||
<li class="nav-item nav-item-1"><a href="index.html" >Python/C API 参考手册</a> »</li>
|
||||
<li class="nav-item nav-item-2"><a href="concrete.html" accesskey="U">具体的对象层</a> »</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="bytes-objects">
|
||||
<span id="bytesobjects"></span><h1>bytes 对象<a class="headerlink" href="#bytes-objects" title="永久链接至标题">¶</a></h1>
|
||||
<p>当期望带一个字节串形参但却带一个非字节串形参被调用时,这些函数会引发 <a class="reference internal" href="../library/exceptions.html#TypeError" title="TypeError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">TypeError</span></code></a>。</p>
|
||||
<span class="target" id="index-0"></span><dl class="type">
|
||||
<dt id="c.PyBytesObject">
|
||||
<code class="sig-name descname">PyBytesObject</code><a class="headerlink" href="#c.PyBytesObject" 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.PyBytes_Type">
|
||||
<a class="reference internal" href="type.html#c.PyTypeObject" title="PyTypeObject">PyTypeObject</a> <code class="sig-name descname">PyBytes_Type</code><a class="headerlink" href="#c.PyBytes_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#bytes" title="bytes"><code class="xref py py-class docutils literal notranslate"><span class="pre">bytes</span></code></a> 是相同的对象。</p>
|
||||
</dd></dl>
|
||||
|
||||
<dl class="function">
|
||||
<dt id="c.PyBytes_Check">
|
||||
int <code class="sig-name descname">PyBytes_Check</code><span class="sig-paren">(</span><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.PyBytes_Check" title="永久链接至目标">¶</a></dt>
|
||||
<dd><p>如果对象 <em>o</em> 是字节对象或字节类型的子类型的实例,则返回 true。</p>
|
||||
</dd></dl>
|
||||
|
||||
<dl class="function">
|
||||
<dt id="c.PyBytes_CheckExact">
|
||||
int <code class="sig-name descname">PyBytes_CheckExact</code><span class="sig-paren">(</span><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.PyBytes_CheckExact" title="永久链接至目标">¶</a></dt>
|
||||
<dd><p>如果对象 <em>o</em> 是字节对象,但不是字节类型子类型的实例,则返回 true。</p>
|
||||
</dd></dl>
|
||||
|
||||
<dl class="function">
|
||||
<dt id="c.PyBytes_FromString">
|
||||
<a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a>* <code class="sig-name descname">PyBytes_FromString</code><span class="sig-paren">(</span>const char<em> *v</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyBytes_FromString" title="永久链接至目标">¶</a></dt>
|
||||
<dd><em class="refcount">Return value: New reference.</em><p>成功时返回一个以字符串 <em>v</em> 的副本为值的新字节串对象,失败时返回 <code class="docutils literal notranslate"><span class="pre">NULL</span></code>。 形参 <em>v</em> 不可为 <code class="docutils literal notranslate"><span class="pre">NULL</span></code>;它不会被检查。</p>
|
||||
</dd></dl>
|
||||
|
||||
<dl class="function">
|
||||
<dt id="c.PyBytes_FromStringAndSize">
|
||||
<a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a>* <code class="sig-name descname">PyBytes_FromStringAndSize</code><span class="sig-paren">(</span>const char<em> *v</em>, Py_ssize_t<em> len</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyBytes_FromStringAndSize" title="永久链接至目标">¶</a></dt>
|
||||
<dd><em class="refcount">Return value: New reference.</em><p>成功时返回一个以字符串 <em>v</em> 的副本为值且长度为 <em>len</em> 的新字节串对象,失败时返回 <code class="docutils literal notranslate"><span class="pre">NULL</span></code>。 如果 <em>v</em> 为 <code class="docutils literal notranslate"><span class="pre">NULL</span></code>,则不初始化字节串对象的内容。</p>
|
||||
</dd></dl>
|
||||
|
||||
<dl class="function">
|
||||
<dt id="c.PyBytes_FromFormat">
|
||||
<a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a>* <code class="sig-name descname">PyBytes_FromFormat</code><span class="sig-paren">(</span>const char<em> *format</em>, ...<span class="sig-paren">)</span><a class="headerlink" href="#c.PyBytes_FromFormat" title="永久链接至目标">¶</a></dt>
|
||||
<dd><em class="refcount">Return value: New reference.</em><p>接受一个 C <code class="xref c c-func docutils literal notranslate"><span class="pre">printf()</span></code> 风格的 <em>format</em> 字符串和可变数量的参数,计算结果 Python 字节串对象的大小并返回参数值经格式化后的字节串对象。 可变数量的参数必须均为 C 类型并且必须恰好与 <em>format</em> 字符串中的格式字符相对应。 允许使用下列格式字符串:</p>
|
||||
<table class="docutils align-default">
|
||||
<colgroup>
|
||||
<col style="width: 29%" />
|
||||
<col style="width: 23%" />
|
||||
<col style="width: 48%" />
|
||||
</colgroup>
|
||||
<thead>
|
||||
<tr class="row-odd"><th class="head"><p>格式字符</p></th>
|
||||
<th class="head"><p>类型</p></th>
|
||||
<th class="head"><p>注释</p></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr class="row-even"><td><p><code class="xref py py-attr docutils literal notranslate"><span class="pre">%%</span></code></p></td>
|
||||
<td><p><em>不适用</em></p></td>
|
||||
<td><p>文字%字符。</p></td>
|
||||
</tr>
|
||||
<tr class="row-odd"><td><p><code class="xref py py-attr docutils literal notranslate"><span class="pre">%c</span></code></p></td>
|
||||
<td><p>int</p></td>
|
||||
<td><p>一个字节,被表示为一个 C 语言的整型</p></td>
|
||||
</tr>
|
||||
<tr class="row-even"><td><p><code class="xref py py-attr docutils literal notranslate"><span class="pre">%d</span></code></p></td>
|
||||
<td><p>int</p></td>
|
||||
<td><p>相当于 <code class="docutils literal notranslate"><span class="pre">printf("%d")</span></code>. <a class="footnote-reference brackets" href="#id9" id="id1">1</a></p></td>
|
||||
</tr>
|
||||
<tr class="row-odd"><td><p><code class="xref py py-attr docutils literal notranslate"><span class="pre">%u</span></code></p></td>
|
||||
<td><p>unsigned int</p></td>
|
||||
<td><p>相当于 <code class="docutils literal notranslate"><span class="pre">printf("%u")</span></code>. <a class="footnote-reference brackets" href="#id9" id="id2">1</a></p></td>
|
||||
</tr>
|
||||
<tr class="row-even"><td><p><code class="xref py py-attr docutils literal notranslate"><span class="pre">%ld</span></code></p></td>
|
||||
<td><p>长整型</p></td>
|
||||
<td><p>相当于 <code class="docutils literal notranslate"><span class="pre">printf("%ld")</span></code>. <a class="footnote-reference brackets" href="#id9" id="id3">1</a></p></td>
|
||||
</tr>
|
||||
<tr class="row-odd"><td><p><code class="xref py py-attr docutils literal notranslate"><span class="pre">%lu</span></code></p></td>
|
||||
<td><p>unsigned long</p></td>
|
||||
<td><p>相当于 <code class="docutils literal notranslate"><span class="pre">printf("%lu")</span></code>. <a class="footnote-reference brackets" href="#id9" id="id4">1</a></p></td>
|
||||
</tr>
|
||||
<tr class="row-even"><td><p><code class="xref py py-attr docutils literal notranslate"><span class="pre">%zd</span></code></p></td>
|
||||
<td><p>Py_ssize_t</p></td>
|
||||
<td><p>相当于 <code class="docutils literal notranslate"><span class="pre">printf("%zd")</span></code>. <a class="footnote-reference brackets" href="#id9" id="id5">1</a></p></td>
|
||||
</tr>
|
||||
<tr class="row-odd"><td><p><code class="xref py py-attr docutils literal notranslate"><span class="pre">%zu</span></code></p></td>
|
||||
<td><p>size_t</p></td>
|
||||
<td><p>相当于 <code class="docutils literal notranslate"><span class="pre">printf("%zu")</span></code>. <a class="footnote-reference brackets" href="#id9" id="id6">1</a></p></td>
|
||||
</tr>
|
||||
<tr class="row-even"><td><p><code class="xref py py-attr docutils literal notranslate"><span class="pre">%i</span></code></p></td>
|
||||
<td><p>int</p></td>
|
||||
<td><p>相当于 <code class="docutils literal notranslate"><span class="pre">printf("%i")</span></code>. <a class="footnote-reference brackets" href="#id9" id="id7">1</a></p></td>
|
||||
</tr>
|
||||
<tr class="row-odd"><td><p><code class="xref py py-attr docutils literal notranslate"><span class="pre">%x</span></code></p></td>
|
||||
<td><p>int</p></td>
|
||||
<td><p>相当于 <code class="docutils literal notranslate"><span class="pre">printf("%x")</span></code>. <a class="footnote-reference brackets" href="#id9" id="id8">1</a></p></td>
|
||||
</tr>
|
||||
<tr class="row-even"><td><p><code class="xref py py-attr docutils literal notranslate"><span class="pre">%s</span></code></p></td>
|
||||
<td><p>const char*</p></td>
|
||||
<td><p>以 null 为终止符的 C 字符数组。</p></td>
|
||||
</tr>
|
||||
<tr class="row-odd"><td><p><code class="xref py py-attr docutils literal notranslate"><span class="pre">%p</span></code></p></td>
|
||||
<td><p>const void*</p></td>
|
||||
<td><p>一个 C 指针的十六进制表示形式。 基本等价于 <code class="docutils literal notranslate"><span class="pre">printf("%p")</span></code> 但它会确保以字面值 <code class="docutils literal notranslate"><span class="pre">0x</span></code> 开头,不论系统平台上 <code class="docutils literal notranslate"><span class="pre">printf</span></code> 的输出是什么。</p></td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<p>无法识别的格式字符会导致将格式字符串的其余所有内容原样复制到结果对象,并丢弃所有多余的参数。</p>
|
||||
<dl class="footnote brackets">
|
||||
<dt class="label" id="id9"><span class="brackets">1</span><span class="fn-backref">(<a href="#id1">1</a>,<a href="#id2">2</a>,<a href="#id3">3</a>,<a href="#id4">4</a>,<a href="#id5">5</a>,<a href="#id6">6</a>,<a href="#id7">7</a>,<a href="#id8">8</a>)</span></dt>
|
||||
<dd><p>对于整数说明符(d,u,ld,lu,zd,zu,i,x):当给出精度时,0 转换标志是有效的。</p>
|
||||
</dd>
|
||||
</dl>
|
||||
</dd></dl>
|
||||
|
||||
<dl class="function">
|
||||
<dt id="c.PyBytes_FromFormatV">
|
||||
<a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a>* <code class="sig-name descname">PyBytes_FromFormatV</code><span class="sig-paren">(</span>const char<em> *format</em>, va_list<em> vargs</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyBytes_FromFormatV" title="永久链接至目标">¶</a></dt>
|
||||
<dd><em class="refcount">Return value: New reference.</em><p>与 <a class="reference internal" href="#c.PyBytes_FromFormat" title="PyBytes_FromFormat"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyBytes_FromFormat()</span></code></a> 完全相同,除了它需要两个参数。</p>
|
||||
</dd></dl>
|
||||
|
||||
<dl class="function">
|
||||
<dt id="c.PyBytes_FromObject">
|
||||
<a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a>* <code class="sig-name descname">PyBytes_FromObject</code><span class="sig-paren">(</span><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.PyBytes_FromObject" title="永久链接至目标">¶</a></dt>
|
||||
<dd><em class="refcount">Return value: New reference.</em><p>返回字节表示实现缓冲区协议的对象*o*。</p>
|
||||
</dd></dl>
|
||||
|
||||
<dl class="function">
|
||||
<dt id="c.PyBytes_Size">
|
||||
Py_ssize_t <code class="sig-name descname">PyBytes_Size</code><span class="sig-paren">(</span><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.PyBytes_Size" title="永久链接至目标">¶</a></dt>
|
||||
<dd><p>返回字节对象*o*中字节的长度。</p>
|
||||
</dd></dl>
|
||||
|
||||
<dl class="function">
|
||||
<dt id="c.PyBytes_GET_SIZE">
|
||||
Py_ssize_t <code class="sig-name descname">PyBytes_GET_SIZE</code><span class="sig-paren">(</span><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.PyBytes_GET_SIZE" title="永久链接至目标">¶</a></dt>
|
||||
<dd><p>宏版本的 <a class="reference internal" href="#c.PyBytes_Size" title="PyBytes_Size"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyBytes_Size()</span></code></a> 但是不带错误检测。</p>
|
||||
</dd></dl>
|
||||
|
||||
<dl class="function">
|
||||
<dt id="c.PyBytes_AsString">
|
||||
char* <code class="sig-name descname">PyBytes_AsString</code><span class="sig-paren">(</span><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.PyBytes_AsString" title="永久链接至目标">¶</a></dt>
|
||||
<dd><p>返回对应 <em>o</em> 的内容的指针。 该指针指向 <em>o</em> 的内部缓冲区,其中包含 <code class="docutils literal notranslate"><span class="pre">len(o)</span> <span class="pre">+</span> <span class="pre">1</span></code> 个字节。 缓冲区的最后一个字节总是为空,不论是否存在其他空字节。 该数据不可通过任何形式来修改,除非是刚使用 <code class="docutils literal notranslate"><span class="pre">PyBytes_FromStringAndSize(NULL,</span> <span class="pre">size)</span></code> 创建该对象。 它不可被撤销分配。 如果 <em>o</em> 根本不是一个字节串对象,则 <a class="reference internal" href="#c.PyBytes_AsString" title="PyBytes_AsString"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyBytes_AsString()</span></code></a> 将返回 <code class="docutils literal notranslate"><span class="pre">NULL</span></code> 并引发 <a class="reference internal" href="../library/exceptions.html#TypeError" title="TypeError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">TypeError</span></code></a>。</p>
|
||||
</dd></dl>
|
||||
|
||||
<dl class="function">
|
||||
<dt id="c.PyBytes_AS_STRING">
|
||||
char* <code class="sig-name descname">PyBytes_AS_STRING</code><span class="sig-paren">(</span><a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a><em> *string</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyBytes_AS_STRING" title="永久链接至目标">¶</a></dt>
|
||||
<dd><p>宏版本的 <a class="reference internal" href="#c.PyBytes_AsString" title="PyBytes_AsString"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyBytes_AsString()</span></code></a> 但是不带错误检测。</p>
|
||||
</dd></dl>
|
||||
|
||||
<dl class="function">
|
||||
<dt id="c.PyBytes_AsStringAndSize">
|
||||
int <code class="sig-name descname">PyBytes_AsStringAndSize</code><span class="sig-paren">(</span><a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a><em> *obj</em>, char<em> **buffer</em>, Py_ssize_t<em> *length</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyBytes_AsStringAndSize" title="永久链接至目标">¶</a></dt>
|
||||
<dd><p>通过输出变量 <em>buffer</em> 和 <em>length</em> 返回以 null 为终止符的对象 <em>obj</em> 的内容。</p>
|
||||
<p>如果 <em>length</em> 为 <code class="docutils literal notranslate"><span class="pre">NULL</span></code>,字节串对象就不包含嵌入的空字节;如果包含,则该函数将返回 <code class="docutils literal notranslate"><span class="pre">-1</span></code> 并引发 <a class="reference internal" href="../library/exceptions.html#ValueError" title="ValueError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">ValueError</span></code></a>。</p>
|
||||
<p>该缓冲区指向 <em>obj</em> 的内部缓冲,它的末尾包含一个额外的空字节(不算在 <em>length</em> 当中)。 该数据不可通过任何方式来修改,除非是刚使用 <code class="docutils literal notranslate"><span class="pre">PyBytes_FromStringAndSize(NULL,</span> <span class="pre">size)</span></code> 创建该对象。 它不可被撤销分配。 如果 <em>obj</em> 根本不是一个字节串对象,则 <a class="reference internal" href="#c.PyBytes_AsStringAndSize" title="PyBytes_AsStringAndSize"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyBytes_AsStringAndSize()</span></code></a> 将返回 <code class="docutils literal notranslate"><span class="pre">-1</span></code> 并引发 <a class="reference internal" href="../library/exceptions.html#TypeError" title="TypeError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">TypeError</span></code></a>。</p>
|
||||
<div class="versionchanged">
|
||||
<p><span class="versionmodified changed">在 3.5 版更改: </span>以前,当字节串对象中出现嵌入的空字节时将引发 <a class="reference internal" href="../library/exceptions.html#TypeError" title="TypeError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">TypeError</span></code></a>。</p>
|
||||
</div>
|
||||
</dd></dl>
|
||||
|
||||
<dl class="function">
|
||||
<dt id="c.PyBytes_Concat">
|
||||
void <code class="sig-name descname">PyBytes_Concat</code><span class="sig-paren">(</span><a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a><em> **bytes</em>, <a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a><em> *newpart</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyBytes_Concat" title="永久链接至目标">¶</a></dt>
|
||||
<dd><p>在 <em>*bytes</em> 中创建新的字节串对象,其中包含添加到 <em>bytes</em> 的 <em>newpart</em> 的内容;调用者将获得新的引用。 对 <em>bytes</em> 原值的引用将被收回。 如果无法创建新对象,对 <em>bytes</em> 的旧引用仍将被丢弃且 <em>*bytes</em> 的值将被设为 <code class="docutils literal notranslate"><span class="pre">NULL</span></code>;并将设置适当的异常。</p>
|
||||
</dd></dl>
|
||||
|
||||
<dl class="function">
|
||||
<dt id="c.PyBytes_ConcatAndDel">
|
||||
void <code class="sig-name descname">PyBytes_ConcatAndDel</code><span class="sig-paren">(</span><a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a><em> **bytes</em>, <a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a><em> *newpart</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyBytes_ConcatAndDel" title="永久链接至目标">¶</a></dt>
|
||||
<dd><p>在 <em>*bytes</em> 中创建新的字节串对象,其中包含添加到 <em>bytes</em> 的 <em>newpart</em> 的内容。 此版本会减少 <em>newpart</em> 的引用计数。</p>
|
||||
</dd></dl>
|
||||
|
||||
<dl class="function">
|
||||
<dt id="c._PyBytes_Resize">
|
||||
int <code class="sig-name descname">_PyBytes_Resize</code><span class="sig-paren">(</span><a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a><em> **bytes</em>, Py_ssize_t<em> newsize</em><span class="sig-paren">)</span><a class="headerlink" href="#c._PyBytes_Resize" title="永久链接至目标">¶</a></dt>
|
||||
<dd><p>改变字节串大小的一种方式,即使其为“不可变对象”。 此方式仅用于创建全新的字节串对象;如果字节串在代码的其他部分已知则不可使用此方式。 如果输入字节串对象的引用计数不为一则调用此函数将报错。 传入一个现有字节串对象的地址作为 lvalue(它可能会被写入),并传入希望的新大小。 当成功时,<em>*bytes</em> 将存放改变大小后的字节串对象并返回 <code class="docutils literal notranslate"><span class="pre">0</span></code>;<em>*bytes</em> 中的地址可能与其输入值不同。 如果重新分配失败,则 <em>*bytes</em> 上的原字节串对象将被撤销分配,<em>*bytes</em> 会被设为 <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> 并返回 <code class="docutils literal notranslate"><span class="pre">-1</span></code>。</p>
|
||||
</dd></dl>
|
||||
|
||||
</section>
|
||||
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="sphinxsidebar" role="navigation" aria-label="main navigation">
|
||||
<div class="sphinxsidebarwrapper">
|
||||
<h4>上一个主题</h4>
|
||||
<p class="topless"><a href="complex.html"
|
||||
title="上一章">复数对象</a></p>
|
||||
<h4>下一个主题</h4>
|
||||
<p class="topless"><a href="bytearray.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/bytes.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="bytearray.html" title="字节数组对象"
|
||||
>下一页</a> |</li>
|
||||
<li class="right" >
|
||||
<a href="complex.html" title="复数对象"
|
||||
>上一页</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> »</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> »
|
||||
</li>
|
||||
|
||||
<li class="nav-item nav-item-1"><a href="index.html" >Python/C API 参考手册</a> »</li>
|
||||
<li class="nav-item nav-item-2"><a href="concrete.html" >具体的对象层</a> »</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">
|
||||
© <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>
|
||||
Reference in New Issue
Block a user