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

587 lines
59 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.
<!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>极高层级 API &#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="refcounting.html" />
<link rel="prev" title="稳定的应用程序二进制接口" href="stable.html" />
<link rel="canonical" href="https://docs.python.org/3/c-api/veryhigh.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="stable.html"
title="上一章">稳定的应用程序二进制接口</a></p>
<h4>下一个主题</h4>
<p class="topless"><a href="refcounting.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/veryhigh.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/veryhigh.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="refcounting.html" title="引用计数"
accesskey="N">下一页</a> |</li>
<li class="right" >
<a href="stable.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> &#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" accesskey="U">Python/C API 参考手册</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="the-very-high-level-layer">
<span id="veryhigh"></span><h1>极高层级 API<a class="headerlink" href="#the-very-high-level-layer" title="永久链接至标题"></a></h1>
<p>本章节的函数将允许你执行在文件或缓冲区中提供的 Python 源代码,但它们将不允许你在更细节化的方式与解释器进行交互。</p>
<p>这些函数中有几个可以接受特定的前缀语法符号作为形参。 可用的前缀符号有 <code class="xref py py-const docutils literal notranslate"><span class="pre">Py_eval_input</span></code>, <code class="xref py py-const docutils literal notranslate"><span class="pre">Py_file_input</span></code> 以及 <code class="xref py py-const docutils literal notranslate"><span class="pre">Py_single_input</span></code>。 这些符号会在接受它们作为形参的函数文档中加以说明。</p>
<p>还要注意这些函数中有几个可以接受 <code class="xref c c-type docutils literal notranslate"><span class="pre">FILE*</span></code> 形参。 有一个需要小心处理的特别问题是针对不同 C 库的 <code class="xref c c-type docutils literal notranslate"><span class="pre">FILE</span></code> 结构体可能是不相同而且不兼容的。 (至少是)在 Windows 中,动态链接的扩展有可能会使用不同的库,所以应当特别注意只有在确定这些函数是由 Python 运行时所使用的相同的库创建的情况下才将 <code class="xref c c-type docutils literal notranslate"><span class="pre">FILE*</span></code> 形参传给它们。</p>
<dl class="function">
<dt id="c.Py_Main">
int <code class="sig-name descname">Py_Main</code><span class="sig-paren">(</span>int<em> argc</em>, wchar_t<em> **argv</em><span class="sig-paren">)</span><a class="headerlink" href="#c.Py_Main" title="永久链接至目标"></a></dt>
<dd><p>针对标准解释器的主程序。 嵌入了 Python 的程序将可使用此程序。 所提供的 <em>argc</em><em>argv</em> 形参应当与传给 C 程序的 <code class="xref c c-func docutils literal notranslate"><span class="pre">main()</span></code> 函数的形参相同(将根据用户的语言区域转换为)。 一个重要的注意事项是参数列表可能会被修改(但参数列表中字符串所指向的内容不会被修改)。 如果解释器正常退出(即未引发异常)则返回值将为 <code class="docutils literal notranslate"><span class="pre">0</span></code>,如果解释器因引发异常而退出则返回 <code class="docutils literal notranslate"><span class="pre">1</span></code>,或者如果形参列表不能表示有效的 Python 命令行则返回 <code class="docutils literal notranslate"><span class="pre">2</span></code></p>
<p>请注意如果引发了一个在其他场合下未处理的 <a class="reference internal" href="../library/exceptions.html#SystemExit" title="SystemExit"><code class="xref py py-exc docutils literal notranslate"><span class="pre">SystemExit</span></code></a>,此函数将不会返回 <code class="docutils literal notranslate"><span class="pre">1</span></code>,而是退出进程,只要 <code class="docutils literal notranslate"><span class="pre">Py_InspectFlag</span></code> 还未被设置。</p>
</dd></dl>
<dl class="function">
<dt id="c.Py_BytesMain">
int <code class="sig-name descname">Py_BytesMain</code><span class="sig-paren">(</span>int<em> argc</em>, char<em> **argv</em><span class="sig-paren">)</span><a class="headerlink" href="#c.Py_BytesMain" title="永久链接至目标"></a></dt>
<dd><p>类似于 <a class="reference internal" href="#c.Py_Main" title="Py_Main"><code class="xref c c-func docutils literal notranslate"><span class="pre">Py_Main()</span></code></a><em>argv</em> 是一个包含字节串的数组。</p>
<div class="versionadded">
<p><span class="versionmodified added">3.8 新版功能.</span></p>
</div>
</dd></dl>
<dl class="function">
<dt id="c.PyRun_AnyFile">
int <code class="sig-name descname">PyRun_AnyFile</code><span class="sig-paren">(</span>FILE<em> *fp</em>, const char<em> *filename</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyRun_AnyFile" title="永久链接至目标"></a></dt>
<dd><p>这是针对下面 <a class="reference internal" href="#c.PyRun_AnyFileExFlags" title="PyRun_AnyFileExFlags"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyRun_AnyFileExFlags()</span></code></a> 的简化版接口,将 <em>closeit</em> 设为 <code class="docutils literal notranslate"><span class="pre">0</span></code> 而将 <em>flags</em> 设为 <code class="docutils literal notranslate"><span class="pre">NULL</span></code></p>
</dd></dl>
<dl class="function">
<dt id="c.PyRun_AnyFileFlags">
int <code class="sig-name descname">PyRun_AnyFileFlags</code><span class="sig-paren">(</span>FILE<em> *fp</em>, const char<em> *filename</em>, <a class="reference internal" href="#c.PyCompilerFlags" title="PyCompilerFlags">PyCompilerFlags</a><em> *flags</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyRun_AnyFileFlags" title="永久链接至目标"></a></dt>
<dd><p>这是针对下面 <a class="reference internal" href="#c.PyRun_AnyFileExFlags" title="PyRun_AnyFileExFlags"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyRun_AnyFileExFlags()</span></code></a> 的简化版接口,将 <em>closeit</em> 参数设为 <code class="docutils literal notranslate"><span class="pre">0</span></code></p>
</dd></dl>
<dl class="function">
<dt id="c.PyRun_AnyFileEx">
int <code class="sig-name descname">PyRun_AnyFileEx</code><span class="sig-paren">(</span>FILE<em> *fp</em>, const char<em> *filename</em>, int<em> closeit</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyRun_AnyFileEx" title="永久链接至目标"></a></dt>
<dd><p>这是针对下面 <a class="reference internal" href="#c.PyRun_AnyFileExFlags" title="PyRun_AnyFileExFlags"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyRun_AnyFileExFlags()</span></code></a> 的简化版接口,将 <em>flags</em> 参数设为 <code class="docutils literal notranslate"><span class="pre">NULL</span></code></p>
</dd></dl>
<dl class="function">
<dt id="c.PyRun_AnyFileExFlags">
int <code class="sig-name descname">PyRun_AnyFileExFlags</code><span class="sig-paren">(</span>FILE<em> *fp</em>, const char<em> *filename</em>, int<em> closeit</em>, <a class="reference internal" href="#c.PyCompilerFlags" title="PyCompilerFlags">PyCompilerFlags</a><em> *flags</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyRun_AnyFileExFlags" title="永久链接至目标"></a></dt>
<dd><p>If <em>fp</em> refers to a file associated with an interactive device (console or
terminal input or Unix pseudo-terminal), return the value of
<a class="reference internal" href="#c.PyRun_InteractiveLoop" title="PyRun_InteractiveLoop"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyRun_InteractiveLoop()</span></code></a>, otherwise return the result of
<a class="reference internal" href="#c.PyRun_SimpleFile" title="PyRun_SimpleFile"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyRun_SimpleFile()</span></code></a>. <em>filename</em> is decoded from the filesystem
encoding (<a class="reference internal" href="../library/sys.html#sys.getfilesystemencoding" title="sys.getfilesystemencoding"><code class="xref py py-func docutils literal notranslate"><span class="pre">sys.getfilesystemencoding()</span></code></a>). If <em>filename</em> is <code class="docutils literal notranslate"><span class="pre">NULL</span></code>, this
function uses <code class="docutils literal notranslate"><span class="pre">&quot;???&quot;</span></code> as the filename.</p>
</dd></dl>
<dl class="function">
<dt id="c.PyRun_SimpleString">
int <code class="sig-name descname">PyRun_SimpleString</code><span class="sig-paren">(</span>const char<em> *command</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyRun_SimpleString" title="永久链接至目标"></a></dt>
<dd><p>这是针对下面 <a class="reference internal" href="#c.PyRun_SimpleStringFlags" title="PyRun_SimpleStringFlags"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyRun_SimpleStringFlags()</span></code></a> 的简化版接口,将 <a class="reference internal" href="#c.PyCompilerFlags" title="PyCompilerFlags"><code class="xref c c-type docutils literal notranslate"><span class="pre">PyCompilerFlags</span></code></a>* 参数设为 <code class="docutils literal notranslate"><span class="pre">NULL</span></code></p>
</dd></dl>
<dl class="function">
<dt id="c.PyRun_SimpleStringFlags">
int <code class="sig-name descname">PyRun_SimpleStringFlags</code><span class="sig-paren">(</span>const char<em> *command</em>, <a class="reference internal" href="#c.PyCompilerFlags" title="PyCompilerFlags">PyCompilerFlags</a><em> *flags</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyRun_SimpleStringFlags" title="永久链接至目标"></a></dt>
<dd><p>根据 <em>flags</em> 参数,在 <a class="reference internal" href="../library/__main__.html#module-__main__" title="__main__: The environment where the top-level script is run."><code class="xref py py-mod docutils literal notranslate"><span class="pre">__main__</span></code></a> 模块中执行 Python 源代码。 如果 <a class="reference internal" href="../library/__main__.html#module-__main__" title="__main__: The environment where the top-level script is run."><code class="xref py py-mod docutils literal notranslate"><span class="pre">__main__</span></code></a> 尚不存在,它将被创建。 成功时返回 <code class="docutils literal notranslate"><span class="pre">0</span></code>,如果引发异常则返回 <code class="docutils literal notranslate"><span class="pre">-1</span></code>。 如果发生错误,则将无法获得异常信息。 对于 <em>flags</em> 的含义,请参阅下文。</p>
<p>请注意如果引发了一个在其他场合下未处理的 <a class="reference internal" href="../library/exceptions.html#SystemExit" title="SystemExit"><code class="xref py py-exc docutils literal notranslate"><span class="pre">SystemExit</span></code></a>,此函数将不会返回 <code class="docutils literal notranslate"><span class="pre">-1</span></code>,而是退出进程,只要 <code class="docutils literal notranslate"><span class="pre">Py_InspectFlag</span></code> 还未被设置。</p>
</dd></dl>
<dl class="function">
<dt id="c.PyRun_SimpleFile">
int <code class="sig-name descname">PyRun_SimpleFile</code><span class="sig-paren">(</span>FILE<em> *fp</em>, const char<em> *filename</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyRun_SimpleFile" title="永久链接至目标"></a></dt>
<dd><p>这是针对下面 <a class="reference internal" href="#c.PyRun_SimpleFileExFlags" title="PyRun_SimpleFileExFlags"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyRun_SimpleFileExFlags()</span></code></a> 的简化版接口,将 <em>closeit</em> 设为 <code class="docutils literal notranslate"><span class="pre">0</span></code> 而将 <em>flags</em> 设为 <code class="docutils literal notranslate"><span class="pre">NULL</span></code></p>
</dd></dl>
<dl class="function">
<dt id="c.PyRun_SimpleFileEx">
int <code class="sig-name descname">PyRun_SimpleFileEx</code><span class="sig-paren">(</span>FILE<em> *fp</em>, const char<em> *filename</em>, int<em> closeit</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyRun_SimpleFileEx" title="永久链接至目标"></a></dt>
<dd><p>这是针对下面 <a class="reference internal" href="#c.PyRun_SimpleFileExFlags" title="PyRun_SimpleFileExFlags"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyRun_SimpleFileExFlags()</span></code></a> 的简化版接口,将 <em>flags</em> 设为 <code class="docutils literal notranslate"><span class="pre">NULL</span></code></p>
</dd></dl>
<dl class="function">
<dt id="c.PyRun_SimpleFileExFlags">
int <code class="sig-name descname">PyRun_SimpleFileExFlags</code><span class="sig-paren">(</span>FILE<em> *fp</em>, const char<em> *filename</em>, int<em> closeit</em>, <a class="reference internal" href="#c.PyCompilerFlags" title="PyCompilerFlags">PyCompilerFlags</a><em> *flags</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyRun_SimpleFileExFlags" title="永久链接至目标"></a></dt>
<dd><p>Similar to <a class="reference internal" href="#c.PyRun_SimpleStringFlags" title="PyRun_SimpleStringFlags"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyRun_SimpleStringFlags()</span></code></a>, but the Python source code is read
from <em>fp</em> instead of an in-memory string. <em>filename</em> should be the name of
the file, it is decoded from the filesystem encoding
(<a class="reference internal" href="../library/sys.html#sys.getfilesystemencoding" title="sys.getfilesystemencoding"><code class="xref py py-func docutils literal notranslate"><span class="pre">sys.getfilesystemencoding()</span></code></a>). If <em>closeit</em> is true, the file is
closed before PyRun_SimpleFileExFlags returns.</p>
<div class="admonition note">
<p class="admonition-title">注解</p>
<p>On Windows, <em>fp</em> should be opened as binary mode (e.g. <code class="docutils literal notranslate"><span class="pre">fopen(filename,</span> <span class="pre">&quot;rb&quot;)</span></code>.
Otherwise, Python may not handle script file with LF line ending correctly.</p>
</div>
</dd></dl>
<dl class="function">
<dt id="c.PyRun_InteractiveOne">
int <code class="sig-name descname">PyRun_InteractiveOne</code><span class="sig-paren">(</span>FILE<em> *fp</em>, const char<em> *filename</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyRun_InteractiveOne" title="永久链接至目标"></a></dt>
<dd><p>这是针对下面 <a class="reference internal" href="#c.PyRun_InteractiveOneFlags" title="PyRun_InteractiveOneFlags"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyRun_InteractiveOneFlags()</span></code></a> 的简化版接口,将 <em>flags</em> 设为 <code class="docutils literal notranslate"><span class="pre">NULL</span></code></p>
</dd></dl>
<dl class="function">
<dt id="c.PyRun_InteractiveOneFlags">
int <code class="sig-name descname">PyRun_InteractiveOneFlags</code><span class="sig-paren">(</span>FILE<em> *fp</em>, const char<em> *filename</em>, <a class="reference internal" href="#c.PyCompilerFlags" title="PyCompilerFlags">PyCompilerFlags</a><em> *flags</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyRun_InteractiveOneFlags" title="永久链接至目标"></a></dt>
<dd><p>Read and execute a single statement from a file associated with an
interactive device according to the <em>flags</em> argument. The user will be
prompted using <code class="docutils literal notranslate"><span class="pre">sys.ps1</span></code> and <code class="docutils literal notranslate"><span class="pre">sys.ps2</span></code>. <em>filename</em> is decoded from the
filesystem encoding (<a class="reference internal" href="../library/sys.html#sys.getfilesystemencoding" title="sys.getfilesystemencoding"><code class="xref py py-func docutils literal notranslate"><span class="pre">sys.getfilesystemencoding()</span></code></a>).</p>
<p>当输入被成功执行时返回 <code class="docutils literal notranslate"><span class="pre">0</span></code>,如果引发异常则返回 <code class="docutils literal notranslate"><span class="pre">-1</span></code>,或者如果存在解析错误则返回来自作为 Python 的组成部分发布的 <code class="file docutils literal notranslate"><span class="pre">errcode.h</span></code> 包括文件的错误代码。 (请注意 <code class="file docutils literal notranslate"><span class="pre">errcode.h</span></code> 并未被 <code class="file docutils literal notranslate"><span class="pre">Python.h</span></code> 所包括,因此如果需要则必须专门地包括。)</p>
</dd></dl>
<dl class="function">
<dt id="c.PyRun_InteractiveLoop">
int <code class="sig-name descname">PyRun_InteractiveLoop</code><span class="sig-paren">(</span>FILE<em> *fp</em>, const char<em> *filename</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyRun_InteractiveLoop" title="永久链接至目标"></a></dt>
<dd><p>这是针对下面 <a class="reference internal" href="#c.PyRun_InteractiveLoopFlags" title="PyRun_InteractiveLoopFlags"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyRun_InteractiveLoopFlags()</span></code></a> 的简化版接口,将 <em>flags</em> 设为 <code class="docutils literal notranslate"><span class="pre">NULL</span></code></p>
</dd></dl>
<dl class="function">
<dt id="c.PyRun_InteractiveLoopFlags">
int <code class="sig-name descname">PyRun_InteractiveLoopFlags</code><span class="sig-paren">(</span>FILE<em> *fp</em>, const char<em> *filename</em>, <a class="reference internal" href="#c.PyCompilerFlags" title="PyCompilerFlags">PyCompilerFlags</a><em> *flags</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyRun_InteractiveLoopFlags" title="永久链接至目标"></a></dt>
<dd><p>Read and execute statements from a file associated with an interactive device
until EOF is reached. The user will be prompted using <code class="docutils literal notranslate"><span class="pre">sys.ps1</span></code> and
<code class="docutils literal notranslate"><span class="pre">sys.ps2</span></code>. <em>filename</em> is decoded from the filesystem encoding
(<a class="reference internal" href="../library/sys.html#sys.getfilesystemencoding" title="sys.getfilesystemencoding"><code class="xref py py-func docutils literal notranslate"><span class="pre">sys.getfilesystemencoding()</span></code></a>). Returns <code class="docutils literal notranslate"><span class="pre">0</span></code> at EOF or a negative
number upon failure.</p>
</dd></dl>
<dl class="var">
<dt id="c.PyOS_InputHook">
int <code class="sig-name descname">(*PyOS_InputHook)</code><span class="sig-paren">(</span>void<span class="sig-paren">)</span><a class="headerlink" href="#c.PyOS_InputHook" title="永久链接至目标"></a></dt>
<dd><p>可以被设为指向一个原型为 <code class="docutils literal notranslate"><span class="pre">int</span> <span class="pre">func(void)</span></code> 的函数。 该函数将在Python 的解释器提示符即将空闲并等待用户从终端输入时被调用。 返回值会被忽略。 重写这个钩子可被用来将解释器的提示符集成到其他事件循环中,就像 Python 码中 <code class="file docutils literal notranslate"><span class="pre">Modules/_tkinter.c</span></code> 所做的那样。</p>
</dd></dl>
<dl class="var">
<dt id="c.PyOS_ReadlineFunctionPointer">
char* <code class="sig-name descname">(*PyOS_ReadlineFunctionPointer)</code><span class="sig-paren">(</span>FILE<em> *</em>, FILE<em> *</em>, const char<em> *</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyOS_ReadlineFunctionPointer" title="永久链接至目标"></a></dt>
<dd><p>可以被设为指向一个原型为 <code class="docutils literal notranslate"><span class="pre">char</span> <span class="pre">*func(FILE</span> <span class="pre">*stdin,</span> <span class="pre">FILE</span> <span class="pre">*stdout,</span> <span class="pre">char</span> <span class="pre">*prompt)</span></code> 的函数,重写被用来读取解释器提示符的一行输入的默认函数。 该函数被预期为如果字符串 <em>prompt</em> 不为 <code class="docutils literal notranslate"><span class="pre">NULL</span></code> 就输出它,然后从所提供的标准输入文件读取一行输入,并返回结果字符串。 例如,<a class="reference internal" href="../library/readline.html#module-readline" title="readline: GNU readline support for Python. (Unix)"><code class="xref py py-mod docutils literal notranslate"><span class="pre">readline</span></code></a> 模块将这个钩子设置为提供行编辑和 tab 键补全等功能。</p>
<p>结果必须是一个由 <a class="reference internal" href="memory.html#c.PyMem_RawMalloc" title="PyMem_RawMalloc"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyMem_RawMalloc()</span></code></a><a class="reference internal" href="memory.html#c.PyMem_RawRealloc" title="PyMem_RawRealloc"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyMem_RawRealloc()</span></code></a> 分配的字符串,或者如果发生错误则为 <code class="docutils literal notranslate"><span class="pre">NULL</span></code></p>
<div class="versionchanged">
<p><span class="versionmodified changed">在 3.4 版更改: </span>结果必须由 <a class="reference internal" href="memory.html#c.PyMem_RawMalloc" title="PyMem_RawMalloc"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyMem_RawMalloc()</span></code></a><a class="reference internal" href="memory.html#c.PyMem_RawRealloc" title="PyMem_RawRealloc"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyMem_RawRealloc()</span></code></a> 分配,而不是由 <a class="reference internal" href="memory.html#c.PyMem_Malloc" title="PyMem_Malloc"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyMem_Malloc()</span></code></a><a class="reference internal" href="memory.html#c.PyMem_Realloc" title="PyMem_Realloc"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyMem_Realloc()</span></code></a> 分配。</p>
</div>
</dd></dl>
<dl class="function">
<dt id="c.PyParser_SimpleParseString">
struct _node* <code class="sig-name descname">PyParser_SimpleParseString</code><span class="sig-paren">(</span>const char<em> *str</em>, int<em> start</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyParser_SimpleParseString" title="永久链接至目标"></a></dt>
<dd><p>This is a simplified interface to
<a class="reference internal" href="#c.PyParser_SimpleParseStringFlagsFilename" title="PyParser_SimpleParseStringFlagsFilename"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyParser_SimpleParseStringFlagsFilename()</span></code></a> below, leaving <em>filename</em> set
to <code class="docutils literal notranslate"><span class="pre">NULL</span></code> and <em>flags</em> set to <code class="docutils literal notranslate"><span class="pre">0</span></code>.</p>
</dd></dl>
<dl class="function">
<dt id="c.PyParser_SimpleParseStringFlags">
struct _node* <code class="sig-name descname">PyParser_SimpleParseStringFlags</code><span class="sig-paren">(</span>const char<em> *str</em>, int<em> start</em>, int<em> flags</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyParser_SimpleParseStringFlags" title="永久链接至目标"></a></dt>
<dd><p>This is a simplified interface to
<a class="reference internal" href="#c.PyParser_SimpleParseStringFlagsFilename" title="PyParser_SimpleParseStringFlagsFilename"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyParser_SimpleParseStringFlagsFilename()</span></code></a> below, leaving <em>filename</em> set
to <code class="docutils literal notranslate"><span class="pre">NULL</span></code>.</p>
</dd></dl>
<dl class="function">
<dt id="c.PyParser_SimpleParseStringFlagsFilename">
struct _node* <code class="sig-name descname">PyParser_SimpleParseStringFlagsFilename</code><span class="sig-paren">(</span>const char<em> *str</em>, const char<em> *filename</em>, int<em> start</em>, int<em> flags</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyParser_SimpleParseStringFlagsFilename" title="永久链接至目标"></a></dt>
<dd><p>Parse Python source code from <em>str</em> using the start token <em>start</em> according to
the <em>flags</em> argument. The result can be used to create a code object which can
be evaluated efficiently. This is useful if a code fragment must be evaluated
many times. <em>filename</em> is decoded from the filesystem encoding
(<a class="reference internal" href="../library/sys.html#sys.getfilesystemencoding" title="sys.getfilesystemencoding"><code class="xref py py-func docutils literal notranslate"><span class="pre">sys.getfilesystemencoding()</span></code></a>).</p>
</dd></dl>
<dl class="function">
<dt id="c.PyParser_SimpleParseFile">
struct _node* <code class="sig-name descname">PyParser_SimpleParseFile</code><span class="sig-paren">(</span>FILE<em> *fp</em>, const char<em> *filename</em>, int<em> start</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyParser_SimpleParseFile" title="永久链接至目标"></a></dt>
<dd><p>This is a simplified interface to <a class="reference internal" href="#c.PyParser_SimpleParseFileFlags" title="PyParser_SimpleParseFileFlags"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyParser_SimpleParseFileFlags()</span></code></a> below,
leaving <em>flags</em> set to <code class="docutils literal notranslate"><span class="pre">0</span></code>.</p>
</dd></dl>
<dl class="function">
<dt id="c.PyParser_SimpleParseFileFlags">
struct _node* <code class="sig-name descname">PyParser_SimpleParseFileFlags</code><span class="sig-paren">(</span>FILE<em> *fp</em>, const char<em> *filename</em>, int<em> start</em>, int<em> flags</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyParser_SimpleParseFileFlags" title="永久链接至目标"></a></dt>
<dd><p>Similar to <a class="reference internal" href="#c.PyParser_SimpleParseStringFlagsFilename" title="PyParser_SimpleParseStringFlagsFilename"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyParser_SimpleParseStringFlagsFilename()</span></code></a>, but the Python
source code is read from <em>fp</em> instead of an in-memory string.</p>
</dd></dl>
<dl class="function">
<dt id="c.PyRun_String">
<a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a>* <code class="sig-name descname">PyRun_String</code><span class="sig-paren">(</span>const char<em> *str</em>, int<em> start</em>, <a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a><em> *globals</em>, <a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a><em> *locals</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyRun_String" title="永久链接至目标"></a></dt>
<dd><em class="refcount">Return value: New reference.</em><p>这是针对下面 <a class="reference internal" href="#c.PyRun_StringFlags" title="PyRun_StringFlags"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyRun_StringFlags()</span></code></a> 的简化版接口,将 <em>flags</em> 设为 <code class="docutils literal notranslate"><span class="pre">NULL</span></code></p>
</dd></dl>
<dl class="function">
<dt id="c.PyRun_StringFlags">
<a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a>* <code class="sig-name descname">PyRun_StringFlags</code><span class="sig-paren">(</span>const char<em> *str</em>, int<em> start</em>, <a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a><em> *globals</em>, <a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a><em> *locals</em>, <a class="reference internal" href="#c.PyCompilerFlags" title="PyCompilerFlags">PyCompilerFlags</a><em> *flags</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyRun_StringFlags" title="永久链接至目标"></a></dt>
<dd><em class="refcount">Return value: New reference.</em><p>在由对象 <em>globals</em><em>locals</em> 指定的上下文中执行来自 <em>str</em> 的 Python 源代码,并使用以 <em>flags</em> 指定的编译器旗标。 <em>globals</em> 必须是一个字典;<em>locals</em> 可以是任何实现了映射协议的对象。 形参 <em>start</em> 指定了应当被用来解析源代码的起始形符。</p>
<p>返回将代码作为 Python 对象执行的结果,或者如果引发了异常则返回 <code class="docutils literal notranslate"><span class="pre">NULL</span></code></p>
</dd></dl>
<dl class="function">
<dt id="c.PyRun_File">
<a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a>* <code class="sig-name descname">PyRun_File</code><span class="sig-paren">(</span>FILE<em> *fp</em>, const char<em> *filename</em>, int<em> start</em>, <a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a><em> *globals</em>, <a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a><em> *locals</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyRun_File" title="永久链接至目标"></a></dt>
<dd><em class="refcount">Return value: New reference.</em><p>这是针对下面 <a class="reference internal" href="#c.PyRun_FileExFlags" title="PyRun_FileExFlags"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyRun_FileExFlags()</span></code></a> 的简化版接口,将 <em>closeit</em> 设为 <code class="docutils literal notranslate"><span class="pre">0</span></code> 并将 <em>flags</em> 设为 <code class="docutils literal notranslate"><span class="pre">NULL</span></code></p>
</dd></dl>
<dl class="function">
<dt id="c.PyRun_FileEx">
<a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a>* <code class="sig-name descname">PyRun_FileEx</code><span class="sig-paren">(</span>FILE<em> *fp</em>, const char<em> *filename</em>, int<em> start</em>, <a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a><em> *globals</em>, <a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a><em> *locals</em>, int<em> closeit</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyRun_FileEx" title="永久链接至目标"></a></dt>
<dd><em class="refcount">Return value: New reference.</em><p>这是针对下面 <a class="reference internal" href="#c.PyRun_FileExFlags" title="PyRun_FileExFlags"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyRun_FileExFlags()</span></code></a> 的简化版接口,将 <em>flags</em> 设为 <code class="docutils literal notranslate"><span class="pre">NULL</span></code></p>
</dd></dl>
<dl class="function">
<dt id="c.PyRun_FileFlags">
<a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a>* <code class="sig-name descname">PyRun_FileFlags</code><span class="sig-paren">(</span>FILE<em> *fp</em>, const char<em> *filename</em>, int<em> start</em>, <a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a><em> *globals</em>, <a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a><em> *locals</em>, <a class="reference internal" href="#c.PyCompilerFlags" title="PyCompilerFlags">PyCompilerFlags</a><em> *flags</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyRun_FileFlags" title="永久链接至目标"></a></dt>
<dd><em class="refcount">Return value: New reference.</em><p>这是针对下面 <a class="reference internal" href="#c.PyRun_FileExFlags" title="PyRun_FileExFlags"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyRun_FileExFlags()</span></code></a> 的简化版接口,将 <em>closeit</em> 设为 <code class="docutils literal notranslate"><span class="pre">0</span></code></p>
</dd></dl>
<dl class="function">
<dt id="c.PyRun_FileExFlags">
<a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a>* <code class="sig-name descname">PyRun_FileExFlags</code><span class="sig-paren">(</span>FILE<em> *fp</em>, const char<em> *filename</em>, int<em> start</em>, <a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a><em> *globals</em>, <a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a><em> *locals</em>, int<em> closeit</em>, <a class="reference internal" href="#c.PyCompilerFlags" title="PyCompilerFlags">PyCompilerFlags</a><em> *flags</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyRun_FileExFlags" title="永久链接至目标"></a></dt>
<dd><em class="refcount">Return value: New reference.</em><p>Similar to <a class="reference internal" href="#c.PyRun_StringFlags" title="PyRun_StringFlags"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyRun_StringFlags()</span></code></a>, but the Python source code is read from
<em>fp</em> instead of an in-memory string. <em>filename</em> should be the name of the file,
it is decoded from the filesystem encoding (<a class="reference internal" href="../library/sys.html#sys.getfilesystemencoding" title="sys.getfilesystemencoding"><code class="xref py py-func docutils literal notranslate"><span class="pre">sys.getfilesystemencoding()</span></code></a>).
If <em>closeit</em> is true, the file is closed before <a class="reference internal" href="#c.PyRun_FileExFlags" title="PyRun_FileExFlags"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyRun_FileExFlags()</span></code></a>
returns.</p>
</dd></dl>
<dl class="function">
<dt id="c.Py_CompileString">
<a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a>* <code class="sig-name descname">Py_CompileString</code><span class="sig-paren">(</span>const char<em> *str</em>, const char<em> *filename</em>, int<em> start</em><span class="sig-paren">)</span><a class="headerlink" href="#c.Py_CompileString" title="永久链接至目标"></a></dt>
<dd><em class="refcount">Return value: New reference.</em><p>这是针对下面 <a class="reference internal" href="#c.Py_CompileStringFlags" title="Py_CompileStringFlags"><code class="xref c c-func docutils literal notranslate"><span class="pre">Py_CompileStringFlags()</span></code></a> 的简化版接口,将 <em>flags</em> 设为 <code class="docutils literal notranslate"><span class="pre">NULL</span></code></p>
</dd></dl>
<dl class="function">
<dt id="c.Py_CompileStringFlags">
<a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a>* <code class="sig-name descname">Py_CompileStringFlags</code><span class="sig-paren">(</span>const char<em> *str</em>, const char<em> *filename</em>, int<em> start</em>, <a class="reference internal" href="#c.PyCompilerFlags" title="PyCompilerFlags">PyCompilerFlags</a><em> *flags</em><span class="sig-paren">)</span><a class="headerlink" href="#c.Py_CompileStringFlags" title="永久链接至目标"></a></dt>
<dd><em class="refcount">Return value: New reference.</em><p>这是针对下面 <a class="reference internal" href="#c.Py_CompileStringExFlags" title="Py_CompileStringExFlags"><code class="xref c c-func docutils literal notranslate"><span class="pre">Py_CompileStringExFlags()</span></code></a> 的简化版接口,将 <em>optimize</em> 设为 <code class="docutils literal notranslate"><span class="pre">-1</span></code></p>
</dd></dl>
<dl class="function">
<dt id="c.Py_CompileStringObject">
<a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a>* <code class="sig-name descname">Py_CompileStringObject</code><span class="sig-paren">(</span>const char<em> *str</em>, <a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a><em> *filename</em>, int<em> start</em>, <a class="reference internal" href="#c.PyCompilerFlags" title="PyCompilerFlags">PyCompilerFlags</a><em> *flags</em>, int<em> optimize</em><span class="sig-paren">)</span><a class="headerlink" href="#c.Py_CompileStringObject" title="永久链接至目标"></a></dt>
<dd><em class="refcount">Return value: New reference.</em><p>解析并编译 <em>str</em> 中的 Python 源代码,返回结果代码对象。 开始形符由 <em>start</em> 给出;这可被用来限制可被编译的代码并且应为 <code class="xref py py-const docutils literal notranslate"><span class="pre">Py_eval_input</span></code>, <code class="xref py py-const docutils literal notranslate"><span class="pre">Py_file_input</span></code><code class="xref py py-const docutils literal notranslate"><span class="pre">Py_single_input</span></code>。 由 <em>filename</em> 指定的文件名会被用来构造代码对象并可能出现在回溯信息或 <a class="reference internal" href="../library/exceptions.html#SyntaxError" title="SyntaxError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">SyntaxError</span></code></a> 异常消息中。 如果代码无法被解析或编译则此函数将返回 <code class="docutils literal notranslate"><span class="pre">NULL</span></code></p>
<p>整数 <em>optimize</em> 指定编译器的优化级别;值 <code class="docutils literal notranslate"><span class="pre">-1</span></code> 将选择与 <a class="reference internal" href="../using/cmdline.html#cmdoption-o"><code class="xref std std-option docutils literal notranslate"><span class="pre">-O</span></code></a> 选项相同的解释器优化级别。 显式级别为 <code class="docutils literal notranslate"><span class="pre">0</span></code> (无优化;<code class="docutils literal notranslate"><span class="pre">__debug__</span></code> 为真值)、<code class="docutils literal notranslate"><span class="pre">1</span></code> (断言被移除,<code class="docutils literal notranslate"><span class="pre">__debug__</span></code> 为假值) 或 <code class="docutils literal notranslate"><span class="pre">2</span></code> (文档字符串也被移除)。</p>
<div class="versionadded">
<p><span class="versionmodified added">3.4 新版功能.</span></p>
</div>
</dd></dl>
<dl class="function">
<dt id="c.Py_CompileStringExFlags">
<a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a>* <code class="sig-name descname">Py_CompileStringExFlags</code><span class="sig-paren">(</span>const char<em> *str</em>, const char<em> *filename</em>, int<em> start</em>, <a class="reference internal" href="#c.PyCompilerFlags" title="PyCompilerFlags">PyCompilerFlags</a><em> *flags</em>, int<em> optimize</em><span class="sig-paren">)</span><a class="headerlink" href="#c.Py_CompileStringExFlags" title="永久链接至目标"></a></dt>
<dd><em class="refcount">Return value: New reference.</em><p>Like <a class="reference internal" href="#c.Py_CompileStringObject" title="Py_CompileStringObject"><code class="xref c c-func docutils literal notranslate"><span class="pre">Py_CompileStringObject()</span></code></a>, but <em>filename</em> is a byte string
decoded from the filesystem encoding (<a class="reference internal" href="../library/os.html#os.fsdecode" title="os.fsdecode"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.fsdecode()</span></code></a>).</p>
<div class="versionadded">
<p><span class="versionmodified added">3.2 新版功能.</span></p>
</div>
</dd></dl>
<dl class="function">
<dt id="c.PyEval_EvalCode">
<a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a>* <code class="sig-name descname">PyEval_EvalCode</code><span class="sig-paren">(</span><a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a><em> *co</em>, <a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a><em> *globals</em>, <a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a><em> *locals</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyEval_EvalCode" title="永久链接至目标"></a></dt>
<dd><em class="refcount">Return value: New reference.</em><p>这是针对 <a class="reference internal" href="#c.PyEval_EvalCodeEx" title="PyEval_EvalCodeEx"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyEval_EvalCodeEx()</span></code></a> 的简化版接口,只附带代码对象,以及全局和局部变量。 其他参数均设为 <code class="docutils literal notranslate"><span class="pre">NULL</span></code></p>
</dd></dl>
<dl class="function">
<dt id="c.PyEval_EvalCodeEx">
<a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a>* <code class="sig-name descname">PyEval_EvalCodeEx</code><span class="sig-paren">(</span><a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a><em> *co</em>, <a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a><em> *globals</em>, <a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a><em> *locals</em>, <a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a> *const<em> *args</em>, int<em> argcount</em>, <a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a> *const<em> *kws</em>, int<em> kwcount</em>, <a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a> *const<em> *defs</em>, int<em> defcount</em>, <a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a><em> *kwdefs</em>, <a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a><em> *closure</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyEval_EvalCodeEx" title="永久链接至目标"></a></dt>
<dd><em class="refcount">Return value: New reference.</em><p>对一个预编译的代码对象求值,为其求值给出特定的环境。 此环境由全局变量的字典,局部变量映射对象,参数、关键字和默认值的数组,<a class="reference internal" href="../glossary.html#keyword-only-parameter"><span class="std std-ref">仅限关键字</span></a> 参数的默认值的字典和单元的封闭元组构成。</p>
</dd></dl>
<dl class="type">
<dt id="c.PyFrameObject">
<code class="sig-name descname">PyFrameObject</code><a class="headerlink" href="#c.PyFrameObject" title="永久链接至目标"></a></dt>
<dd><p>用于描述帧对象的 C 对象结构体。 此类型的字段可能在任何时候被改变。</p>
</dd></dl>
<dl class="function">
<dt id="c.PyEval_EvalFrame">
<a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a>* <code class="sig-name descname">PyEval_EvalFrame</code><span class="sig-paren">(</span><a class="reference internal" href="#c.PyFrameObject" title="PyFrameObject">PyFrameObject</a><em> *f</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyEval_EvalFrame" title="永久链接至目标"></a></dt>
<dd><em class="refcount">Return value: New reference.</em><p>对一个执行帧求值。 这是针对 <a class="reference internal" href="#c.PyEval_EvalFrameEx" title="PyEval_EvalFrameEx"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyEval_EvalFrameEx()</span></code></a> 的简化版接口,用于保持向下兼容性。</p>
</dd></dl>
<dl class="function">
<dt id="c.PyEval_EvalFrameEx">
<a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a>* <code class="sig-name descname">PyEval_EvalFrameEx</code><span class="sig-paren">(</span><a class="reference internal" href="#c.PyFrameObject" title="PyFrameObject">PyFrameObject</a><em> *f</em>, int<em> throwflag</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyEval_EvalFrameEx" title="永久链接至目标"></a></dt>
<dd><em class="refcount">Return value: New reference.</em><p>这是 Python 解释运行不带修饰的主函数。 与执行帧 <em>f</em> 相关联的代码对象将被执行,解释字节码并根据需要执行调用。 额外的 <em>throwflag</em> 形参基本可以被忽略 —— 如果为真值,则会导致立即抛出一个异常;这会被用于生成器对象的 <a class="reference internal" href="../reference/expressions.html#generator.throw" title="generator.throw"><code class="xref py py-meth docutils literal notranslate"><span class="pre">throw()</span></code></a> 方法。</p>
<div class="versionchanged">
<p><span class="versionmodified changed">在 3.4 版更改: </span>该函数现在包含一个调试断言,用以确保不会静默地丢弃活动的异常。</p>
</div>
</dd></dl>
<dl class="function">
<dt id="c.PyEval_MergeCompilerFlags">
int <code class="sig-name descname">PyEval_MergeCompilerFlags</code><span class="sig-paren">(</span><a class="reference internal" href="#c.PyCompilerFlags" title="PyCompilerFlags">PyCompilerFlags</a><em> *cf</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyEval_MergeCompilerFlags" title="永久链接至目标"></a></dt>
<dd><p>此函数会修改当前求值帧的旗标,并在成功时返回真值,失败时返回假值。</p>
</dd></dl>
<dl class="var">
<dt id="c.Py_eval_input">
int <code class="sig-name descname">Py_eval_input</code><a class="headerlink" href="#c.Py_eval_input" title="永久链接至目标"></a></dt>
<dd><p id="index-0">Python 语法中用于孤立表达式的起始符号;配合 <a class="reference internal" href="#c.Py_CompileString" title="Py_CompileString"><code class="xref c c-func docutils literal notranslate"><span class="pre">Py_CompileString()</span></code></a> 使用。</p>
</dd></dl>
<dl class="var">
<dt id="c.Py_file_input">
int <code class="sig-name descname">Py_file_input</code><a class="headerlink" href="#c.Py_file_input" title="永久链接至目标"></a></dt>
<dd><p id="index-1">Python 语法中用于从文件或其他源读取语句序列的起始符号;配合 <a class="reference internal" href="#c.Py_CompileString" title="Py_CompileString"><code class="xref c c-func docutils literal notranslate"><span class="pre">Py_CompileString()</span></code></a> 使用。 这是在编译任意长的 Python 源代码时要使用的符号。</p>
</dd></dl>
<dl class="var">
<dt id="c.Py_single_input">
int <code class="sig-name descname">Py_single_input</code><a class="headerlink" href="#c.Py_single_input" title="永久链接至目标"></a></dt>
<dd><p id="index-2">Python 语法中用于单独语句的起始符号;配合 <a class="reference internal" href="#c.Py_CompileString" title="Py_CompileString"><code class="xref c c-func docutils literal notranslate"><span class="pre">Py_CompileString()</span></code></a> 使用。 这是用于交互式解释器循环的符号。</p>
</dd></dl>
<dl class="type">
<dt id="c.PyCompilerFlags">
struct <code class="sig-name descname">PyCompilerFlags</code><a class="headerlink" href="#c.PyCompilerFlags" title="永久链接至目标"></a></dt>
<dd><p>这是用来存放编译器旗标的结构体。 对于代码仅被编译的情况,它将作为 <code class="docutils literal notranslate"><span class="pre">int</span> <span class="pre">flags</span></code> 传入,而对于代码要被执行的情况,它将作为 <code class="docutils literal notranslate"><span class="pre">PyCompilerFlags</span> <span class="pre">*flags</span></code> 传入。 在这种情况下,<code class="docutils literal notranslate"><span class="pre">from</span> <span class="pre">__future__</span> <span class="pre">import</span></code> 可以修改 <em>flags</em></p>
<p><code class="docutils literal notranslate"><span class="pre">PyCompilerFlags</span> <span class="pre">*flags</span></code><code class="docutils literal notranslate"><span class="pre">NULL</span></code> 时,<code class="xref py py-attr docutils literal notranslate"><span class="pre">cf_flags</span></code> 将被当作等于 <code class="docutils literal notranslate"><span class="pre">0</span></code> 来处理,而任何 <code class="docutils literal notranslate"><span class="pre">from</span> <span class="pre">__future__</span> <span class="pre">import</span></code> 所导致的修改都会被丢弃。</p>
<dl class="member">
<dt id="c.PyCompilerFlags.cf_flags">
int <code class="sig-name descname">cf_flags</code><a class="headerlink" href="#c.PyCompilerFlags.cf_flags" title="永久链接至目标"></a></dt>
<dd><p>编译器旗标。</p>
</dd></dl>
<dl class="member">
<dt id="c.PyCompilerFlags.cf_feature_version">
int <code class="sig-name descname">cf_feature_version</code><a class="headerlink" href="#c.PyCompilerFlags.cf_feature_version" title="永久链接至目标"></a></dt>
<dd><p><em>cf_feature_version</em> 是 Python 的小版本号。 它应当被初始化为 <code class="docutils literal notranslate"><span class="pre">PY_MINOR_VERSION</span></code></p>
<p>此字段默认会被忽略,当且仅当在 <em>cf_flags</em> 中设置了 <code class="docutils literal notranslate"><span class="pre">PyCF_ONLY_AST</span></code> 旗标它才会被使用。</p>
</dd></dl>
<div class="versionchanged">
<p><span class="versionmodified changed">在 3.8 版更改: </span>增加了 <em>cf_feature_version</em> 字段。</p>
</div>
</dd></dl>
<dl class="var">
<dt id="c.CO_FUTURE_DIVISION">
int <code class="sig-name descname">CO_FUTURE_DIVISION</code><a class="headerlink" href="#c.CO_FUTURE_DIVISION" title="永久链接至目标"></a></dt>
<dd><p>这个标志位可在 <em>flags</em> 中设置以使得除法运算符 <code class="docutils literal notranslate"><span class="pre">/</span></code> 被解读为 <span class="target" id="index-5"></span><a class="pep reference external" href="https://www.python.org/dev/peps/pep-0238"><strong>PEP 238</strong></a> 所规定的“真除法”。</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="stable.html"
title="上一章">稳定的应用程序二进制接口</a></p>
<h4>下一个主题</h4>
<p class="topless"><a href="refcounting.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/veryhigh.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="refcounting.html" title="引用计数"
>下一页</a> |</li>
<li class="right" >
<a href="stable.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> &#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="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>