gooderp18绿色标准版
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

708 lines
85KB

  1. <!DOCTYPE html>
  2. <html lang="en" data-content_root="../">
  3. <head>
  4. <meta charset="utf-8" />
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="viewport" content="width=device-width, initial-scale=1" />
  6. <meta property="og:title" content="The Very High Level Layer" />
  7. <meta property="og:type" content="website" />
  8. <meta property="og:url" content="https://docs.python.org/3/c-api/veryhigh.html" />
  9. <meta property="og:site_name" content="Python documentation" />
  10. <meta property="og:description" content="The functions in this chapter will let you execute Python source code given in a file or a buffer, but they will not let you interact in a more detailed way with the interpreter. Several of these f..." />
  11. <meta property="og:image" content="https://docs.python.org/3/_static/og-image.png" />
  12. <meta property="og:image:alt" content="Python documentation" />
  13. <meta name="description" content="The functions in this chapter will let you execute Python source code given in a file or a buffer, but they will not let you interact in a more detailed way with the interpreter. Several of these f..." />
  14. <meta property="og:image:width" content="200" />
  15. <meta property="og:image:height" content="200" />
  16. <meta name="theme-color" content="#3776ab" />
  17. <title>The Very High Level Layer &#8212; Python 3.12.3 documentation</title><meta name="viewport" content="width=device-width, initial-scale=1.0">
  18. <link rel="stylesheet" type="text/css" href="../_static/pygments.css?v=80d5e7a1" />
  19. <link rel="stylesheet" type="text/css" href="../_static/pydoctheme.css?v=bb723527" />
  20. <link id="pygments_dark_css" media="(prefers-color-scheme: dark)" rel="stylesheet" type="text/css" href="../_static/pygments_dark.css?v=b20cc3f5" />
  21. <script src="../_static/documentation_options.js?v=2c828074"></script>
  22. <script src="../_static/doctools.js?v=888ff710"></script>
  23. <script src="../_static/sphinx_highlight.js?v=dc90522c"></script>
  24. <script src="../_static/sidebar.js"></script>
  25. <link rel="search" type="application/opensearchdescription+xml"
  26. title="Search within Python 3.12.3 documentation"
  27. href="../_static/opensearch.xml"/>
  28. <link rel="author" title="About these documents" href="../about.html" />
  29. <link rel="index" title="Index" href="../genindex.html" />
  30. <link rel="search" title="Search" href="../search.html" />
  31. <link rel="copyright" title="Copyright" href="../copyright.html" />
  32. <link rel="next" title="Reference Counting" href="refcounting.html" />
  33. <link rel="prev" title="C API Stability" href="stable.html" />
  34. <link rel="canonical" href="https://docs.python.org/3/c-api/veryhigh.html" />
  35. <style>
  36. @media only screen {
  37. table.full-width-table {
  38. width: 100%;
  39. }
  40. }
  41. </style>
  42. <link rel="stylesheet" href="../_static/pydoctheme_dark.css" media="(prefers-color-scheme: dark)" id="pydoctheme_dark_css">
  43. <link rel="shortcut icon" type="image/png" href="../_static/py.svg" />
  44. <script type="text/javascript" src="../_static/copybutton.js"></script>
  45. <script type="text/javascript" src="../_static/menu.js"></script>
  46. <script type="text/javascript" src="../_static/search-focus.js"></script>
  47. <script type="text/javascript" src="../_static/themetoggle.js"></script>
  48. </head>
  49. <body>
  50. <div class="mobile-nav">
  51. <input type="checkbox" id="menuToggler" class="toggler__input" aria-controls="navigation"
  52. aria-pressed="false" aria-expanded="false" role="button" aria-label="Menu" />
  53. <nav class="nav-content" role="navigation">
  54. <label for="menuToggler" class="toggler__label">
  55. <span></span>
  56. </label>
  57. <span class="nav-items-wrapper">
  58. <a href="https://www.python.org/" class="nav-logo">
  59. <img src="../_static/py.svg" alt="Python logo"/>
  60. </a>
  61. <span class="version_switcher_placeholder"></span>
  62. <form role="search" class="search" action="../search.html" method="get">
  63. <svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" class="search-icon">
  64. <path fill-rule="nonzero" fill="currentColor" 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"></path>
  65. </svg>
  66. <input placeholder="Quick search" aria-label="Quick search" type="search" name="q" />
  67. <input type="submit" value="Go"/>
  68. </form>
  69. </span>
  70. </nav>
  71. <div class="menu-wrapper">
  72. <nav class="menu" role="navigation" aria-label="main navigation">
  73. <div class="language_switcher_placeholder"></div>
  74. <label class="theme-selector-label">
  75. Theme
  76. <select class="theme-selector" oninput="activateTheme(this.value)">
  77. <option value="auto" selected>Auto</option>
  78. <option value="light">Light</option>
  79. <option value="dark">Dark</option>
  80. </select>
  81. </label>
  82. <div>
  83. <h4>Previous topic</h4>
  84. <p class="topless"><a href="stable.html"
  85. title="previous chapter">C API Stability</a></p>
  86. </div>
  87. <div>
  88. <h4>Next topic</h4>
  89. <p class="topless"><a href="refcounting.html"
  90. title="next chapter">Reference Counting</a></p>
  91. </div>
  92. <div role="note" aria-label="source link">
  93. <h3>This Page</h3>
  94. <ul class="this-page-menu">
  95. <li><a href="../bugs.html">Report a Bug</a></li>
  96. <li>
  97. <a href="https://github.com/python/cpython/blob/main/Doc/c-api/veryhigh.rst"
  98. rel="nofollow">Show Source
  99. </a>
  100. </li>
  101. </ul>
  102. </div>
  103. </nav>
  104. </div>
  105. </div>
  106. <div class="related" role="navigation" aria-label="related navigation">
  107. <h3>Navigation</h3>
  108. <ul>
  109. <li class="right" style="margin-right: 10px">
  110. <a href="../genindex.html" title="General Index"
  111. accesskey="I">index</a></li>
  112. <li class="right" >
  113. <a href="../py-modindex.html" title="Python Module Index"
  114. >modules</a> |</li>
  115. <li class="right" >
  116. <a href="refcounting.html" title="Reference Counting"
  117. accesskey="N">next</a> |</li>
  118. <li class="right" >
  119. <a href="stable.html" title="C API Stability"
  120. accesskey="P">previous</a> |</li>
  121. <li><img src="../_static/py.svg" alt="Python logo" style="vertical-align: middle; margin-top: -1px"/></li>
  122. <li><a href="https://www.python.org/">Python</a> &#187;</li>
  123. <li class="switchers">
  124. <div class="language_switcher_placeholder"></div>
  125. <div class="version_switcher_placeholder"></div>
  126. </li>
  127. <li>
  128. </li>
  129. <li id="cpython-language-and-version">
  130. <a href="../index.html">3.12.3 Documentation</a> &#187;
  131. </li>
  132. <li class="nav-item nav-item-1"><a href="index.html" accesskey="U">Python/C API Reference Manual</a> &#187;</li>
  133. <li class="nav-item nav-item-this"><a href="">The Very High Level Layer</a></li>
  134. <li class="right">
  135. <div class="inline-search" role="search">
  136. <form class="inline-search" action="../search.html" method="get">
  137. <input placeholder="Quick search" aria-label="Quick search" type="search" name="q" id="search-box" />
  138. <input type="submit" value="Go" />
  139. </form>
  140. </div>
  141. |
  142. </li>
  143. <li class="right">
  144. <label class="theme-selector-label">
  145. Theme
  146. <select class="theme-selector" oninput="activateTheme(this.value)">
  147. <option value="auto" selected>Auto</option>
  148. <option value="light">Light</option>
  149. <option value="dark">Dark</option>
  150. </select>
  151. </label> |</li>
  152. </ul>
  153. </div>
  154. <div class="document">
  155. <div class="documentwrapper">
  156. <div class="bodywrapper">
  157. <div class="body" role="main">
  158. <section id="the-very-high-level-layer">
  159. <span id="veryhigh"></span><h1>The Very High Level Layer<a class="headerlink" href="#the-very-high-level-layer" title="Link to this heading">¶</a></h1>
  160. <p>The functions in this chapter will let you execute Python source code given in a
  161. file or a buffer, but they will not let you interact in a more detailed way with
  162. the interpreter.</p>
  163. <p>Several of these functions accept a start symbol from the grammar as a
  164. parameter. The available start symbols are <a class="reference internal" href="#c.Py_eval_input" title="Py_eval_input"><code class="xref c c-data docutils literal notranslate"><span class="pre">Py_eval_input</span></code></a>,
  165. <a class="reference internal" href="#c.Py_file_input" title="Py_file_input"><code class="xref c c-data docutils literal notranslate"><span class="pre">Py_file_input</span></code></a>, and <a class="reference internal" href="#c.Py_single_input" title="Py_single_input"><code class="xref c c-data docutils literal notranslate"><span class="pre">Py_single_input</span></code></a>. These are described
  166. following the functions which accept them as parameters.</p>
  167. <p>Note also that several of these functions take <span class="c-expr sig sig-inline c"><span class="n">FILE</span><span class="p">*</span></span> parameters. One
  168. particular issue which needs to be handled carefully is that the <code class="xref c c-type docutils literal notranslate"><span class="pre">FILE</span></code>
  169. structure for different C libraries can be different and incompatible. Under
  170. Windows (at least), it is possible for dynamically linked extensions to actually
  171. use different libraries, so care should be taken that <span class="c-expr sig sig-inline c"><span class="n">FILE</span><span class="p">*</span></span> parameters
  172. are only passed to these functions if it is certain that they were created by
  173. the same library that the Python runtime is using.</p>
  174. <dl class="c function">
  175. <dt class="sig sig-object c" id="c.Py_Main">
  176. <span class="kt"><span class="pre">int</span></span><span class="w"> </span><span class="sig-name descname"><span class="n"><span class="pre">Py_Main</span></span></span><span class="sig-paren">(</span><span class="kt"><span class="pre">int</span></span><span class="w"> </span><span class="n"><span class="pre">argc</span></span>, <span class="n"><span class="pre">wchar_t</span></span><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">argv</span></span><span class="sig-paren">)</span><a class="headerlink" href="#c.Py_Main" title="Link to this definition">¶</a><br /></dt>
  177. <dd><em class="stableabi"> Part of the <a class="reference internal" href="stable.html#stable"><span class="std std-ref">Stable ABI</span></a>.</em><p>The main program for the standard interpreter. This is made available for
  178. programs which embed Python. The <em>argc</em> and <em>argv</em> parameters should be
  179. prepared exactly as those which are passed to a C program’s <code class="xref c c-func docutils literal notranslate"><span class="pre">main()</span></code>
  180. function (converted to wchar_t according to the user’s locale). It is
  181. important to note that the argument list may be modified (but the contents of
  182. the strings pointed to by the argument list are not). The return value will
  183. be <code class="docutils literal notranslate"><span class="pre">0</span></code> if the interpreter exits normally (i.e., without an exception),
  184. <code class="docutils literal notranslate"><span class="pre">1</span></code> if the interpreter exits due to an exception, or <code class="docutils literal notranslate"><span class="pre">2</span></code> if the parameter
  185. list does not represent a valid Python command line.</p>
  186. <p>Note that if an otherwise unhandled <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> is raised, this
  187. function will not return <code class="docutils literal notranslate"><span class="pre">1</span></code>, but exit the process, as long as
  188. <a class="reference internal" href="init_config.html#c.PyConfig.inspect" title="PyConfig.inspect"><code class="xref c c-member docutils literal notranslate"><span class="pre">PyConfig.inspect</span></code></a> is zero.</p>
  189. </dd></dl>
  190. <dl class="c function">
  191. <dt class="sig sig-object c" id="c.Py_BytesMain">
  192. <span class="kt"><span class="pre">int</span></span><span class="w"> </span><span class="sig-name descname"><span class="n"><span class="pre">Py_BytesMain</span></span></span><span class="sig-paren">(</span><span class="kt"><span class="pre">int</span></span><span class="w"> </span><span class="n"><span class="pre">argc</span></span>, <span class="kt"><span class="pre">char</span></span><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">argv</span></span><span class="sig-paren">)</span><a class="headerlink" href="#c.Py_BytesMain" title="Link to this definition">¶</a><br /></dt>
  193. <dd><em class="stableabi"> Part of the <a class="reference internal" href="stable.html#stable"><span class="std std-ref">Stable ABI</span></a> since version 3.8.</em><p>Similar to <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> but <em>argv</em> is an array of bytes strings.</p>
  194. <div class="versionadded">
  195. <p><span class="versionmodified added">New in version 3.8.</span></p>
  196. </div>
  197. </dd></dl>
  198. <dl class="c function">
  199. <dt class="sig sig-object c" id="c.PyRun_AnyFile">
  200. <span class="kt"><span class="pre">int</span></span><span class="w"> </span><span class="sig-name descname"><span class="n"><span class="pre">PyRun_AnyFile</span></span></span><span class="sig-paren">(</span><span class="n"><span class="pre">FILE</span></span><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">fp</span></span>, <span class="k"><span class="pre">const</span></span><span class="w"> </span><span class="kt"><span class="pre">char</span></span><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">filename</span></span><span class="sig-paren">)</span><a class="headerlink" href="#c.PyRun_AnyFile" title="Link to this definition">¶</a><br /></dt>
  201. <dd><p>This is a simplified interface to <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> below, leaving
  202. <em>closeit</em> set to <code class="docutils literal notranslate"><span class="pre">0</span></code> and <em>flags</em> set to <code class="docutils literal notranslate"><span class="pre">NULL</span></code>.</p>
  203. </dd></dl>
  204. <dl class="c function">
  205. <dt class="sig sig-object c" id="c.PyRun_AnyFileFlags">
  206. <span class="kt"><span class="pre">int</span></span><span class="w"> </span><span class="sig-name descname"><span class="n"><span class="pre">PyRun_AnyFileFlags</span></span></span><span class="sig-paren">(</span><span class="n"><span class="pre">FILE</span></span><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">fp</span></span>, <span class="k"><span class="pre">const</span></span><span class="w"> </span><span class="kt"><span class="pre">char</span></span><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">filename</span></span>, <a class="reference internal" href="#c.PyCompilerFlags" title="PyCompilerFlags"><span class="n"><span class="pre">PyCompilerFlags</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">flags</span></span><span class="sig-paren">)</span><a class="headerlink" href="#c.PyRun_AnyFileFlags" title="Link to this definition">¶</a><br /></dt>
  207. <dd><p>This is a simplified interface to <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> below, leaving
  208. the <em>closeit</em> argument set to <code class="docutils literal notranslate"><span class="pre">0</span></code>.</p>
  209. </dd></dl>
  210. <dl class="c function">
  211. <dt class="sig sig-object c" id="c.PyRun_AnyFileEx">
  212. <span class="kt"><span class="pre">int</span></span><span class="w"> </span><span class="sig-name descname"><span class="n"><span class="pre">PyRun_AnyFileEx</span></span></span><span class="sig-paren">(</span><span class="n"><span class="pre">FILE</span></span><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">fp</span></span>, <span class="k"><span class="pre">const</span></span><span class="w"> </span><span class="kt"><span class="pre">char</span></span><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">filename</span></span>, <span class="kt"><span class="pre">int</span></span><span class="w"> </span><span class="n"><span class="pre">closeit</span></span><span class="sig-paren">)</span><a class="headerlink" href="#c.PyRun_AnyFileEx" title="Link to this definition">¶</a><br /></dt>
  213. <dd><p>This is a simplified interface to <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> below, leaving
  214. the <em>flags</em> argument set to <code class="docutils literal notranslate"><span class="pre">NULL</span></code>.</p>
  215. </dd></dl>
  216. <dl class="c function">
  217. <dt class="sig sig-object c" id="c.PyRun_AnyFileExFlags">
  218. <span class="kt"><span class="pre">int</span></span><span class="w"> </span><span class="sig-name descname"><span class="n"><span class="pre">PyRun_AnyFileExFlags</span></span></span><span class="sig-paren">(</span><span class="n"><span class="pre">FILE</span></span><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">fp</span></span>, <span class="k"><span class="pre">const</span></span><span class="w"> </span><span class="kt"><span class="pre">char</span></span><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">filename</span></span>, <span class="kt"><span class="pre">int</span></span><span class="w"> </span><span class="n"><span class="pre">closeit</span></span>, <a class="reference internal" href="#c.PyCompilerFlags" title="PyCompilerFlags"><span class="n"><span class="pre">PyCompilerFlags</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">flags</span></span><span class="sig-paren">)</span><a class="headerlink" href="#c.PyRun_AnyFileExFlags" title="Link to this definition">¶</a><br /></dt>
  219. <dd><p>If <em>fp</em> refers to a file associated with an interactive device (console or
  220. terminal input or Unix pseudo-terminal), return the value of
  221. <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
  222. <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
  223. 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
  224. function uses <code class="docutils literal notranslate"><span class="pre">&quot;???&quot;</span></code> as the filename.
  225. If <em>closeit</em> is true, the file is closed before
  226. <code class="docutils literal notranslate"><span class="pre">PyRun_SimpleFileExFlags()</span></code> returns.</p>
  227. </dd></dl>
  228. <dl class="c function">
  229. <dt class="sig sig-object c" id="c.PyRun_SimpleString">
  230. <span class="kt"><span class="pre">int</span></span><span class="w"> </span><span class="sig-name descname"><span class="n"><span class="pre">PyRun_SimpleString</span></span></span><span class="sig-paren">(</span><span class="k"><span class="pre">const</span></span><span class="w"> </span><span class="kt"><span class="pre">char</span></span><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">command</span></span><span class="sig-paren">)</span><a class="headerlink" href="#c.PyRun_SimpleString" title="Link to this definition">¶</a><br /></dt>
  231. <dd><p>This is a simplified interface 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> below,
  232. leaving the <a class="reference internal" href="#c.PyCompilerFlags" title="PyCompilerFlags"><code class="xref c c-struct docutils literal notranslate"><span class="pre">PyCompilerFlags</span></code></a>* argument set to <code class="docutils literal notranslate"><span class="pre">NULL</span></code>.</p>
  233. </dd></dl>
  234. <dl class="c function">
  235. <dt class="sig sig-object c" id="c.PyRun_SimpleStringFlags">
  236. <span class="kt"><span class="pre">int</span></span><span class="w"> </span><span class="sig-name descname"><span class="n"><span class="pre">PyRun_SimpleStringFlags</span></span></span><span class="sig-paren">(</span><span class="k"><span class="pre">const</span></span><span class="w"> </span><span class="kt"><span class="pre">char</span></span><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">command</span></span>, <a class="reference internal" href="#c.PyCompilerFlags" title="PyCompilerFlags"><span class="n"><span class="pre">PyCompilerFlags</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">flags</span></span><span class="sig-paren">)</span><a class="headerlink" href="#c.PyRun_SimpleStringFlags" title="Link to this definition">¶</a><br /></dt>
  237. <dd><p>Executes the Python source code from <em>command</em> in the <a class="reference internal" href="../library/__main__.html#module-__main__" title="__main__: The environment where top-level code is run. Covers command-line interfaces, import-time behavior, and ``__name__ == '__main__'``."><code class="xref py py-mod docutils literal notranslate"><span class="pre">__main__</span></code></a> module
  238. according to the <em>flags</em> argument. If <a class="reference internal" href="../library/__main__.html#module-__main__" title="__main__: The environment where top-level code is run. Covers command-line interfaces, import-time behavior, and ``__name__ == '__main__'``."><code class="xref py py-mod docutils literal notranslate"><span class="pre">__main__</span></code></a> does not already exist, it
  239. is created. Returns <code class="docutils literal notranslate"><span class="pre">0</span></code> on success or <code class="docutils literal notranslate"><span class="pre">-1</span></code> if an exception was raised. If
  240. there was an error, there is no way to get the exception information. For the
  241. meaning of <em>flags</em>, see below.</p>
  242. <p>Note that if an otherwise unhandled <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> is raised, this
  243. function will not return <code class="docutils literal notranslate"><span class="pre">-1</span></code>, but exit the process, as long as
  244. <a class="reference internal" href="init_config.html#c.PyConfig.inspect" title="PyConfig.inspect"><code class="xref c c-member docutils literal notranslate"><span class="pre">PyConfig.inspect</span></code></a> is zero.</p>
  245. </dd></dl>
  246. <dl class="c function">
  247. <dt class="sig sig-object c" id="c.PyRun_SimpleFile">
  248. <span class="kt"><span class="pre">int</span></span><span class="w"> </span><span class="sig-name descname"><span class="n"><span class="pre">PyRun_SimpleFile</span></span></span><span class="sig-paren">(</span><span class="n"><span class="pre">FILE</span></span><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">fp</span></span>, <span class="k"><span class="pre">const</span></span><span class="w"> </span><span class="kt"><span class="pre">char</span></span><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">filename</span></span><span class="sig-paren">)</span><a class="headerlink" href="#c.PyRun_SimpleFile" title="Link to this definition">¶</a><br /></dt>
  249. <dd><p>This is a simplified interface to <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> below,
  250. leaving <em>closeit</em> set to <code class="docutils literal notranslate"><span class="pre">0</span></code> and <em>flags</em> set to <code class="docutils literal notranslate"><span class="pre">NULL</span></code>.</p>
  251. </dd></dl>
  252. <dl class="c function">
  253. <dt class="sig sig-object c" id="c.PyRun_SimpleFileEx">
  254. <span class="kt"><span class="pre">int</span></span><span class="w"> </span><span class="sig-name descname"><span class="n"><span class="pre">PyRun_SimpleFileEx</span></span></span><span class="sig-paren">(</span><span class="n"><span class="pre">FILE</span></span><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">fp</span></span>, <span class="k"><span class="pre">const</span></span><span class="w"> </span><span class="kt"><span class="pre">char</span></span><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">filename</span></span>, <span class="kt"><span class="pre">int</span></span><span class="w"> </span><span class="n"><span class="pre">closeit</span></span><span class="sig-paren">)</span><a class="headerlink" href="#c.PyRun_SimpleFileEx" title="Link to this definition">¶</a><br /></dt>
  255. <dd><p>This is a simplified interface to <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> below,
  256. leaving <em>flags</em> set to <code class="docutils literal notranslate"><span class="pre">NULL</span></code>.</p>
  257. </dd></dl>
  258. <dl class="c function">
  259. <dt class="sig sig-object c" id="c.PyRun_SimpleFileExFlags">
  260. <span class="kt"><span class="pre">int</span></span><span class="w"> </span><span class="sig-name descname"><span class="n"><span class="pre">PyRun_SimpleFileExFlags</span></span></span><span class="sig-paren">(</span><span class="n"><span class="pre">FILE</span></span><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">fp</span></span>, <span class="k"><span class="pre">const</span></span><span class="w"> </span><span class="kt"><span class="pre">char</span></span><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">filename</span></span>, <span class="kt"><span class="pre">int</span></span><span class="w"> </span><span class="n"><span class="pre">closeit</span></span>, <a class="reference internal" href="#c.PyCompilerFlags" title="PyCompilerFlags"><span class="n"><span class="pre">PyCompilerFlags</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">flags</span></span><span class="sig-paren">)</span><a class="headerlink" href="#c.PyRun_SimpleFileExFlags" title="Link to this definition">¶</a><br /></dt>
  261. <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
  262. from <em>fp</em> instead of an in-memory string. <em>filename</em> should be the name of
  263. the file, it is decoded from <a class="reference internal" href="../glossary.html#term-filesystem-encoding-and-error-handler"><span class="xref std std-term">filesystem encoding and error handler</span></a>.
  264. If <em>closeit</em> is true, the file is closed before
  265. <code class="docutils literal notranslate"><span class="pre">PyRun_SimpleFileExFlags()</span></code> returns.</p>
  266. <div class="admonition note">
  267. <p class="admonition-title">Note</p>
  268. <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>).
  269. Otherwise, Python may not handle script file with LF line ending correctly.</p>
  270. </div>
  271. </dd></dl>
  272. <dl class="c function">
  273. <dt class="sig sig-object c" id="c.PyRun_InteractiveOne">
  274. <span class="kt"><span class="pre">int</span></span><span class="w"> </span><span class="sig-name descname"><span class="n"><span class="pre">PyRun_InteractiveOne</span></span></span><span class="sig-paren">(</span><span class="n"><span class="pre">FILE</span></span><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">fp</span></span>, <span class="k"><span class="pre">const</span></span><span class="w"> </span><span class="kt"><span class="pre">char</span></span><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">filename</span></span><span class="sig-paren">)</span><a class="headerlink" href="#c.PyRun_InteractiveOne" title="Link to this definition">¶</a><br /></dt>
  275. <dd><p>This is a simplified interface to <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> below,
  276. leaving <em>flags</em> set to <code class="docutils literal notranslate"><span class="pre">NULL</span></code>.</p>
  277. </dd></dl>
  278. <dl class="c function">
  279. <dt class="sig sig-object c" id="c.PyRun_InteractiveOneFlags">
  280. <span class="kt"><span class="pre">int</span></span><span class="w"> </span><span class="sig-name descname"><span class="n"><span class="pre">PyRun_InteractiveOneFlags</span></span></span><span class="sig-paren">(</span><span class="n"><span class="pre">FILE</span></span><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">fp</span></span>, <span class="k"><span class="pre">const</span></span><span class="w"> </span><span class="kt"><span class="pre">char</span></span><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">filename</span></span>, <a class="reference internal" href="#c.PyCompilerFlags" title="PyCompilerFlags"><span class="n"><span class="pre">PyCompilerFlags</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">flags</span></span><span class="sig-paren">)</span><a class="headerlink" href="#c.PyRun_InteractiveOneFlags" title="Link to this definition">¶</a><br /></dt>
  281. <dd><p>Read and execute a single statement from a file associated with an
  282. interactive device according to the <em>flags</em> argument. The user will be
  283. 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
  284. <a class="reference internal" href="../glossary.html#term-filesystem-encoding-and-error-handler"><span class="xref std std-term">filesystem encoding and error handler</span></a>.</p>
  285. <p>Returns <code class="docutils literal notranslate"><span class="pre">0</span></code> when the input was
  286. executed successfully, <code class="docutils literal notranslate"><span class="pre">-1</span></code> if there was an exception, or an error code
  287. from the <code class="file docutils literal notranslate"><span class="pre">errcode.h</span></code> include file distributed as part of Python if
  288. there was a parse error. (Note that <code class="file docutils literal notranslate"><span class="pre">errcode.h</span></code> is not included by
  289. <code class="file docutils literal notranslate"><span class="pre">Python.h</span></code>, so must be included specifically if needed.)</p>
  290. </dd></dl>
  291. <dl class="c function">
  292. <dt class="sig sig-object c" id="c.PyRun_InteractiveLoop">
  293. <span class="kt"><span class="pre">int</span></span><span class="w"> </span><span class="sig-name descname"><span class="n"><span class="pre">PyRun_InteractiveLoop</span></span></span><span class="sig-paren">(</span><span class="n"><span class="pre">FILE</span></span><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">fp</span></span>, <span class="k"><span class="pre">const</span></span><span class="w"> </span><span class="kt"><span class="pre">char</span></span><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">filename</span></span><span class="sig-paren">)</span><a class="headerlink" href="#c.PyRun_InteractiveLoop" title="Link to this definition">¶</a><br /></dt>
  294. <dd><p>This is a simplified interface to <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> below,
  295. leaving <em>flags</em> set to <code class="docutils literal notranslate"><span class="pre">NULL</span></code>.</p>
  296. </dd></dl>
  297. <dl class="c function">
  298. <dt class="sig sig-object c" id="c.PyRun_InteractiveLoopFlags">
  299. <span class="kt"><span class="pre">int</span></span><span class="w"> </span><span class="sig-name descname"><span class="n"><span class="pre">PyRun_InteractiveLoopFlags</span></span></span><span class="sig-paren">(</span><span class="n"><span class="pre">FILE</span></span><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">fp</span></span>, <span class="k"><span class="pre">const</span></span><span class="w"> </span><span class="kt"><span class="pre">char</span></span><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">filename</span></span>, <a class="reference internal" href="#c.PyCompilerFlags" title="PyCompilerFlags"><span class="n"><span class="pre">PyCompilerFlags</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">flags</span></span><span class="sig-paren">)</span><a class="headerlink" href="#c.PyRun_InteractiveLoopFlags" title="Link to this definition">¶</a><br /></dt>
  300. <dd><p>Read and execute statements from a file associated with an interactive device
  301. until EOF is reached. The user will be prompted using <code class="docutils literal notranslate"><span class="pre">sys.ps1</span></code> and
  302. <code class="docutils literal notranslate"><span class="pre">sys.ps2</span></code>. <em>filename</em> is decoded from the <a class="reference internal" href="../glossary.html#term-filesystem-encoding-and-error-handler"><span class="xref std std-term">filesystem encoding and
  303. error handler</span></a>. Returns <code class="docutils literal notranslate"><span class="pre">0</span></code> at EOF or a negative number upon failure.</p>
  304. </dd></dl>
  305. <dl class="c var">
  306. <dt class="sig sig-object c" id="c.PyOS_InputHook">
  307. <span class="kt"><span class="pre">int</span></span><span class="w"> </span><span class="p"><span class="pre">(</span></span><span class="p"><span class="pre">*</span></span><span class="sig-name descname"><span class="n"><span class="pre">PyOS_InputHook</span></span></span><span class="p"><span class="pre">)</span></span><span class="p"><span class="pre">(</span></span><span class="kt"><span class="pre">void</span></span><span class="p"><span class="pre">)</span></span><a class="headerlink" href="#c.PyOS_InputHook" title="Link to this definition">¶</a><br /></dt>
  308. <dd><em class="stableabi"> Part of the <a class="reference internal" href="stable.html#stable"><span class="std std-ref">Stable ABI</span></a>.</em><p>Can be set to point to a function with the prototype
  309. <code class="docutils literal notranslate"><span class="pre">int</span> <span class="pre">func(void)</span></code>. The function will be called when Python’s
  310. interpreter prompt is about to become idle and wait for user input
  311. from the terminal. The return value is ignored. Overriding this
  312. hook can be used to integrate the interpreter’s prompt with other
  313. event loops, as done in the <code class="file docutils literal notranslate"><span class="pre">Modules/_tkinter.c</span></code> in the
  314. Python source code.</p>
  315. <div class="versionchanged">
  316. <p><span class="versionmodified changed">Changed in version 3.12: </span>This function is only called from the
  317. <a class="reference internal" href="init.html#sub-interpreter-support"><span class="std std-ref">main interpreter</span></a>.</p>
  318. </div>
  319. </dd></dl>
  320. <dl class="c var">
  321. <dt class="sig sig-object c" id="c.PyOS_ReadlineFunctionPointer">
  322. <span class="kt"><span class="pre">char</span></span><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="p"><span class="pre">(</span></span><span class="p"><span class="pre">*</span></span><span class="sig-name descname"><span class="n"><span class="pre">PyOS_ReadlineFunctionPointer</span></span></span><span class="p"><span class="pre">)</span></span><span class="p"><span class="pre">(</span></span><span class="n"><span class="pre">FILE</span></span><span class="p"><span class="pre">*</span></span><span class="p"><span class="pre">,</span></span><span class="w"> </span><span class="n"><span class="pre">FILE</span></span><span class="p"><span class="pre">*</span></span><span class="p"><span class="pre">,</span></span><span class="w"> </span><span class="k"><span class="pre">const</span></span><span class="w"> </span><span class="kt"><span class="pre">char</span></span><span class="p"><span class="pre">*</span></span><span class="p"><span class="pre">)</span></span><a class="headerlink" href="#c.PyOS_ReadlineFunctionPointer" title="Link to this definition">¶</a><br /></dt>
  323. <dd><p>Can be set to point to a function with the prototype
  324. <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>,
  325. overriding the default function used to read a single line of input
  326. at the interpreter’s prompt. The function is expected to output
  327. the string <em>prompt</em> if it’s not <code class="docutils literal notranslate"><span class="pre">NULL</span></code>, and then read a line of
  328. input from the provided standard input file, returning the
  329. resulting string. For example, The <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> module sets
  330. this hook to provide line-editing and tab-completion features.</p>
  331. <p>The result must be a string allocated by <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> or
  332. <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>, or <code class="docutils literal notranslate"><span class="pre">NULL</span></code> if an error occurred.</p>
  333. <div class="versionchanged">
  334. <p><span class="versionmodified changed">Changed in version 3.4: </span>The result must be allocated by <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> or
  335. <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>, instead of being allocated by
  336. <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> or <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>
  337. </div>
  338. <div class="versionchanged">
  339. <p><span class="versionmodified changed">Changed in version 3.12: </span>This function is only called from the
  340. <a class="reference internal" href="init.html#sub-interpreter-support"><span class="std std-ref">main interpreter</span></a>.</p>
  341. </div>
  342. </dd></dl>
  343. <dl class="c function">
  344. <dt class="sig sig-object c" id="c.PyRun_String">
  345. <a class="reference internal" href="structures.html#c.PyObject" title="PyObject"><span class="n"><span class="pre">PyObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="sig-name descname"><span class="n"><span class="pre">PyRun_String</span></span></span><span class="sig-paren">(</span><span class="k"><span class="pre">const</span></span><span class="w"> </span><span class="kt"><span class="pre">char</span></span><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">str</span></span>, <span class="kt"><span class="pre">int</span></span><span class="w"> </span><span class="n"><span class="pre">start</span></span>, <a class="reference internal" href="structures.html#c.PyObject" title="PyObject"><span class="n"><span class="pre">PyObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">globals</span></span>, <a class="reference internal" href="structures.html#c.PyObject" title="PyObject"><span class="n"><span class="pre">PyObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">locals</span></span><span class="sig-paren">)</span><a class="headerlink" href="#c.PyRun_String" title="Link to this definition">¶</a><br /></dt>
  346. <dd><em class="refcount">Return value: New reference.</em><p>This is a simplified interface 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> below, leaving
  347. <em>flags</em> set to <code class="docutils literal notranslate"><span class="pre">NULL</span></code>.</p>
  348. </dd></dl>
  349. <dl class="c function">
  350. <dt class="sig sig-object c" id="c.PyRun_StringFlags">
  351. <a class="reference internal" href="structures.html#c.PyObject" title="PyObject"><span class="n"><span class="pre">PyObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="sig-name descname"><span class="n"><span class="pre">PyRun_StringFlags</span></span></span><span class="sig-paren">(</span><span class="k"><span class="pre">const</span></span><span class="w"> </span><span class="kt"><span class="pre">char</span></span><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">str</span></span>, <span class="kt"><span class="pre">int</span></span><span class="w"> </span><span class="n"><span class="pre">start</span></span>, <a class="reference internal" href="structures.html#c.PyObject" title="PyObject"><span class="n"><span class="pre">PyObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">globals</span></span>, <a class="reference internal" href="structures.html#c.PyObject" title="PyObject"><span class="n"><span class="pre">PyObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">locals</span></span>, <a class="reference internal" href="#c.PyCompilerFlags" title="PyCompilerFlags"><span class="n"><span class="pre">PyCompilerFlags</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">flags</span></span><span class="sig-paren">)</span><a class="headerlink" href="#c.PyRun_StringFlags" title="Link to this definition">¶</a><br /></dt>
  352. <dd><em class="refcount">Return value: New reference.</em><p>Execute Python source code from <em>str</em> in the context specified by the
  353. objects <em>globals</em> and <em>locals</em> with the compiler flags specified by
  354. <em>flags</em>. <em>globals</em> must be a dictionary; <em>locals</em> can be any object
  355. that implements the mapping protocol. The parameter <em>start</em> specifies
  356. the start token that should be used to parse the source code.</p>
  357. <p>Returns the result of executing the code as a Python object, or <code class="docutils literal notranslate"><span class="pre">NULL</span></code> if an
  358. exception was raised.</p>
  359. </dd></dl>
  360. <dl class="c function">
  361. <dt class="sig sig-object c" id="c.PyRun_File">
  362. <a class="reference internal" href="structures.html#c.PyObject" title="PyObject"><span class="n"><span class="pre">PyObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="sig-name descname"><span class="n"><span class="pre">PyRun_File</span></span></span><span class="sig-paren">(</span><span class="n"><span class="pre">FILE</span></span><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">fp</span></span>, <span class="k"><span class="pre">const</span></span><span class="w"> </span><span class="kt"><span class="pre">char</span></span><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">filename</span></span>, <span class="kt"><span class="pre">int</span></span><span class="w"> </span><span class="n"><span class="pre">start</span></span>, <a class="reference internal" href="structures.html#c.PyObject" title="PyObject"><span class="n"><span class="pre">PyObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">globals</span></span>, <a class="reference internal" href="structures.html#c.PyObject" title="PyObject"><span class="n"><span class="pre">PyObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">locals</span></span><span class="sig-paren">)</span><a class="headerlink" href="#c.PyRun_File" title="Link to this definition">¶</a><br /></dt>
  363. <dd><em class="refcount">Return value: New reference.</em><p>This is a simplified interface to <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> below, leaving
  364. <em>closeit</em> set to <code class="docutils literal notranslate"><span class="pre">0</span></code> and <em>flags</em> set to <code class="docutils literal notranslate"><span class="pre">NULL</span></code>.</p>
  365. </dd></dl>
  366. <dl class="c function">
  367. <dt class="sig sig-object c" id="c.PyRun_FileEx">
  368. <a class="reference internal" href="structures.html#c.PyObject" title="PyObject"><span class="n"><span class="pre">PyObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="sig-name descname"><span class="n"><span class="pre">PyRun_FileEx</span></span></span><span class="sig-paren">(</span><span class="n"><span class="pre">FILE</span></span><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">fp</span></span>, <span class="k"><span class="pre">const</span></span><span class="w"> </span><span class="kt"><span class="pre">char</span></span><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">filename</span></span>, <span class="kt"><span class="pre">int</span></span><span class="w"> </span><span class="n"><span class="pre">start</span></span>, <a class="reference internal" href="structures.html#c.PyObject" title="PyObject"><span class="n"><span class="pre">PyObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">globals</span></span>, <a class="reference internal" href="structures.html#c.PyObject" title="PyObject"><span class="n"><span class="pre">PyObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">locals</span></span>, <span class="kt"><span class="pre">int</span></span><span class="w"> </span><span class="n"><span class="pre">closeit</span></span><span class="sig-paren">)</span><a class="headerlink" href="#c.PyRun_FileEx" title="Link to this definition">¶</a><br /></dt>
  369. <dd><em class="refcount">Return value: New reference.</em><p>This is a simplified interface to <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> below, leaving
  370. <em>flags</em> set to <code class="docutils literal notranslate"><span class="pre">NULL</span></code>.</p>
  371. </dd></dl>
  372. <dl class="c function">
  373. <dt class="sig sig-object c" id="c.PyRun_FileFlags">
  374. <a class="reference internal" href="structures.html#c.PyObject" title="PyObject"><span class="n"><span class="pre">PyObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="sig-name descname"><span class="n"><span class="pre">PyRun_FileFlags</span></span></span><span class="sig-paren">(</span><span class="n"><span class="pre">FILE</span></span><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">fp</span></span>, <span class="k"><span class="pre">const</span></span><span class="w"> </span><span class="kt"><span class="pre">char</span></span><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">filename</span></span>, <span class="kt"><span class="pre">int</span></span><span class="w"> </span><span class="n"><span class="pre">start</span></span>, <a class="reference internal" href="structures.html#c.PyObject" title="PyObject"><span class="n"><span class="pre">PyObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">globals</span></span>, <a class="reference internal" href="structures.html#c.PyObject" title="PyObject"><span class="n"><span class="pre">PyObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">locals</span></span>, <a class="reference internal" href="#c.PyCompilerFlags" title="PyCompilerFlags"><span class="n"><span class="pre">PyCompilerFlags</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">flags</span></span><span class="sig-paren">)</span><a class="headerlink" href="#c.PyRun_FileFlags" title="Link to this definition">¶</a><br /></dt>
  375. <dd><em class="refcount">Return value: New reference.</em><p>This is a simplified interface to <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> below, leaving
  376. <em>closeit</em> set to <code class="docutils literal notranslate"><span class="pre">0</span></code>.</p>
  377. </dd></dl>
  378. <dl class="c function">
  379. <dt class="sig sig-object c" id="c.PyRun_FileExFlags">
  380. <a class="reference internal" href="structures.html#c.PyObject" title="PyObject"><span class="n"><span class="pre">PyObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="sig-name descname"><span class="n"><span class="pre">PyRun_FileExFlags</span></span></span><span class="sig-paren">(</span><span class="n"><span class="pre">FILE</span></span><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">fp</span></span>, <span class="k"><span class="pre">const</span></span><span class="w"> </span><span class="kt"><span class="pre">char</span></span><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">filename</span></span>, <span class="kt"><span class="pre">int</span></span><span class="w"> </span><span class="n"><span class="pre">start</span></span>, <a class="reference internal" href="structures.html#c.PyObject" title="PyObject"><span class="n"><span class="pre">PyObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">globals</span></span>, <a class="reference internal" href="structures.html#c.PyObject" title="PyObject"><span class="n"><span class="pre">PyObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">locals</span></span>, <span class="kt"><span class="pre">int</span></span><span class="w"> </span><span class="n"><span class="pre">closeit</span></span>, <a class="reference internal" href="#c.PyCompilerFlags" title="PyCompilerFlags"><span class="n"><span class="pre">PyCompilerFlags</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">flags</span></span><span class="sig-paren">)</span><a class="headerlink" href="#c.PyRun_FileExFlags" title="Link to this definition">¶</a><br /></dt>
  381. <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
  382. <em>fp</em> instead of an in-memory string. <em>filename</em> should be the name of the file,
  383. it is decoded from the <a class="reference internal" href="../glossary.html#term-filesystem-encoding-and-error-handler"><span class="xref std std-term">filesystem encoding and error handler</span></a>.
  384. 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>
  385. returns.</p>
  386. </dd></dl>
  387. <dl class="c function">
  388. <dt class="sig sig-object c" id="c.Py_CompileString">
  389. <a class="reference internal" href="structures.html#c.PyObject" title="PyObject"><span class="n"><span class="pre">PyObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="sig-name descname"><span class="n"><span class="pre">Py_CompileString</span></span></span><span class="sig-paren">(</span><span class="k"><span class="pre">const</span></span><span class="w"> </span><span class="kt"><span class="pre">char</span></span><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">str</span></span>, <span class="k"><span class="pre">const</span></span><span class="w"> </span><span class="kt"><span class="pre">char</span></span><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">filename</span></span>, <span class="kt"><span class="pre">int</span></span><span class="w"> </span><span class="n"><span class="pre">start</span></span><span class="sig-paren">)</span><a class="headerlink" href="#c.Py_CompileString" title="Link to this definition">¶</a><br /></dt>
  390. <dd><em class="refcount">Return value: New reference.</em><em class="stableabi"> Part of the <a class="reference internal" href="stable.html#stable"><span class="std std-ref">Stable ABI</span></a>.</em><p>This is a simplified interface to <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> below, leaving
  391. <em>flags</em> set to <code class="docutils literal notranslate"><span class="pre">NULL</span></code>.</p>
  392. </dd></dl>
  393. <dl class="c function">
  394. <dt class="sig sig-object c" id="c.Py_CompileStringFlags">
  395. <a class="reference internal" href="structures.html#c.PyObject" title="PyObject"><span class="n"><span class="pre">PyObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="sig-name descname"><span class="n"><span class="pre">Py_CompileStringFlags</span></span></span><span class="sig-paren">(</span><span class="k"><span class="pre">const</span></span><span class="w"> </span><span class="kt"><span class="pre">char</span></span><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">str</span></span>, <span class="k"><span class="pre">const</span></span><span class="w"> </span><span class="kt"><span class="pre">char</span></span><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">filename</span></span>, <span class="kt"><span class="pre">int</span></span><span class="w"> </span><span class="n"><span class="pre">start</span></span>, <a class="reference internal" href="#c.PyCompilerFlags" title="PyCompilerFlags"><span class="n"><span class="pre">PyCompilerFlags</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">flags</span></span><span class="sig-paren">)</span><a class="headerlink" href="#c.Py_CompileStringFlags" title="Link to this definition">¶</a><br /></dt>
  396. <dd><em class="refcount">Return value: New reference.</em><p>This is a simplified interface to <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> below, with
  397. <em>optimize</em> set to <code class="docutils literal notranslate"><span class="pre">-1</span></code>.</p>
  398. </dd></dl>
  399. <dl class="c function">
  400. <dt class="sig sig-object c" id="c.Py_CompileStringObject">
  401. <a class="reference internal" href="structures.html#c.PyObject" title="PyObject"><span class="n"><span class="pre">PyObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="sig-name descname"><span class="n"><span class="pre">Py_CompileStringObject</span></span></span><span class="sig-paren">(</span><span class="k"><span class="pre">const</span></span><span class="w"> </span><span class="kt"><span class="pre">char</span></span><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">str</span></span>, <a class="reference internal" href="structures.html#c.PyObject" title="PyObject"><span class="n"><span class="pre">PyObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">filename</span></span>, <span class="kt"><span class="pre">int</span></span><span class="w"> </span><span class="n"><span class="pre">start</span></span>, <a class="reference internal" href="#c.PyCompilerFlags" title="PyCompilerFlags"><span class="n"><span class="pre">PyCompilerFlags</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">flags</span></span>, <span class="kt"><span class="pre">int</span></span><span class="w"> </span><span class="n"><span class="pre">optimize</span></span><span class="sig-paren">)</span><a class="headerlink" href="#c.Py_CompileStringObject" title="Link to this definition">¶</a><br /></dt>
  402. <dd><em class="refcount">Return value: New reference.</em><p>Parse and compile the Python source code in <em>str</em>, returning the resulting code
  403. object. The start token is given by <em>start</em>; this can be used to constrain the
  404. code which can be compiled and should be <a class="reference internal" href="#c.Py_eval_input" title="Py_eval_input"><code class="xref c c-data docutils literal notranslate"><span class="pre">Py_eval_input</span></code></a>,
  405. <a class="reference internal" href="#c.Py_file_input" title="Py_file_input"><code class="xref c c-data docutils literal notranslate"><span class="pre">Py_file_input</span></code></a>, or <a class="reference internal" href="#c.Py_single_input" title="Py_single_input"><code class="xref c c-data docutils literal notranslate"><span class="pre">Py_single_input</span></code></a>. The filename specified by
  406. <em>filename</em> is used to construct the code object and may appear in tracebacks or
  407. <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> exception messages. This returns <code class="docutils literal notranslate"><span class="pre">NULL</span></code> if the code
  408. cannot be parsed or compiled.</p>
  409. <p>The integer <em>optimize</em> specifies the optimization level of the compiler; a
  410. value of <code class="docutils literal notranslate"><span class="pre">-1</span></code> selects the optimization level of the interpreter as given by
  411. <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> options. Explicit levels are <code class="docutils literal notranslate"><span class="pre">0</span></code> (no optimization;
  412. <code class="docutils literal notranslate"><span class="pre">__debug__</span></code> is true), <code class="docutils literal notranslate"><span class="pre">1</span></code> (asserts are removed, <code class="docutils literal notranslate"><span class="pre">__debug__</span></code> is false)
  413. or <code class="docutils literal notranslate"><span class="pre">2</span></code> (docstrings are removed too).</p>
  414. <div class="versionadded">
  415. <p><span class="versionmodified added">New in version 3.4.</span></p>
  416. </div>
  417. </dd></dl>
  418. <dl class="c function">
  419. <dt class="sig sig-object c" id="c.Py_CompileStringExFlags">
  420. <a class="reference internal" href="structures.html#c.PyObject" title="PyObject"><span class="n"><span class="pre">PyObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="sig-name descname"><span class="n"><span class="pre">Py_CompileStringExFlags</span></span></span><span class="sig-paren">(</span><span class="k"><span class="pre">const</span></span><span class="w"> </span><span class="kt"><span class="pre">char</span></span><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">str</span></span>, <span class="k"><span class="pre">const</span></span><span class="w"> </span><span class="kt"><span class="pre">char</span></span><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">filename</span></span>, <span class="kt"><span class="pre">int</span></span><span class="w"> </span><span class="n"><span class="pre">start</span></span>, <a class="reference internal" href="#c.PyCompilerFlags" title="PyCompilerFlags"><span class="n"><span class="pre">PyCompilerFlags</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">flags</span></span>, <span class="kt"><span class="pre">int</span></span><span class="w"> </span><span class="n"><span class="pre">optimize</span></span><span class="sig-paren">)</span><a class="headerlink" href="#c.Py_CompileStringExFlags" title="Link to this definition">¶</a><br /></dt>
  421. <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
  422. decoded from the <a class="reference internal" href="../glossary.html#term-filesystem-encoding-and-error-handler"><span class="xref std std-term">filesystem encoding and error handler</span></a>.</p>
  423. <div class="versionadded">
  424. <p><span class="versionmodified added">New in version 3.2.</span></p>
  425. </div>
  426. </dd></dl>
  427. <dl class="c function">
  428. <dt class="sig sig-object c" id="c.PyEval_EvalCode">
  429. <a class="reference internal" href="structures.html#c.PyObject" title="PyObject"><span class="n"><span class="pre">PyObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="sig-name descname"><span class="n"><span class="pre">PyEval_EvalCode</span></span></span><span class="sig-paren">(</span><a class="reference internal" href="structures.html#c.PyObject" title="PyObject"><span class="n"><span class="pre">PyObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">co</span></span>, <a class="reference internal" href="structures.html#c.PyObject" title="PyObject"><span class="n"><span class="pre">PyObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">globals</span></span>, <a class="reference internal" href="structures.html#c.PyObject" title="PyObject"><span class="n"><span class="pre">PyObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">locals</span></span><span class="sig-paren">)</span><a class="headerlink" href="#c.PyEval_EvalCode" title="Link to this definition">¶</a><br /></dt>
  430. <dd><em class="refcount">Return value: New reference.</em><em class="stableabi"> Part of the <a class="reference internal" href="stable.html#stable"><span class="std std-ref">Stable ABI</span></a>.</em><p>This is a simplified interface to <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>, with just
  431. the code object, and global and local variables. The other arguments are
  432. set to <code class="docutils literal notranslate"><span class="pre">NULL</span></code>.</p>
  433. </dd></dl>
  434. <dl class="c function">
  435. <dt class="sig sig-object c" id="c.PyEval_EvalCodeEx">
  436. <a class="reference internal" href="structures.html#c.PyObject" title="PyObject"><span class="n"><span class="pre">PyObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="sig-name descname"><span class="n"><span class="pre">PyEval_EvalCodeEx</span></span></span><span class="sig-paren">(</span><a class="reference internal" href="structures.html#c.PyObject" title="PyObject"><span class="n"><span class="pre">PyObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">co</span></span>, <a class="reference internal" href="structures.html#c.PyObject" title="PyObject"><span class="n"><span class="pre">PyObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">globals</span></span>, <a class="reference internal" href="structures.html#c.PyObject" title="PyObject"><span class="n"><span class="pre">PyObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">locals</span></span>, <a class="reference internal" href="structures.html#c.PyObject" title="PyObject"><span class="n"><span class="pre">PyObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="k"><span class="pre">const</span></span><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">args</span></span>, <span class="kt"><span class="pre">int</span></span><span class="w"> </span><span class="n"><span class="pre">argcount</span></span>, <a class="reference internal" href="structures.html#c.PyObject" title="PyObject"><span class="n"><span class="pre">PyObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="k"><span class="pre">const</span></span><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">kws</span></span>, <span class="kt"><span class="pre">int</span></span><span class="w"> </span><span class="n"><span class="pre">kwcount</span></span>, <a class="reference internal" href="structures.html#c.PyObject" title="PyObject"><span class="n"><span class="pre">PyObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="k"><span class="pre">const</span></span><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">defs</span></span>, <span class="kt"><span class="pre">int</span></span><span class="w"> </span><span class="n"><span class="pre">defcount</span></span>, <a class="reference internal" href="structures.html#c.PyObject" title="PyObject"><span class="n"><span class="pre">PyObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">kwdefs</span></span>, <a class="reference internal" href="structures.html#c.PyObject" title="PyObject"><span class="n"><span class="pre">PyObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">closure</span></span><span class="sig-paren">)</span><a class="headerlink" href="#c.PyEval_EvalCodeEx" title="Link to this definition">¶</a><br /></dt>
  437. <dd><em class="refcount">Return value: New reference.</em><em class="stableabi"> Part of the <a class="reference internal" href="stable.html#stable"><span class="std std-ref">Stable ABI</span></a>.</em><p>Evaluate a precompiled code object, given a particular environment for its
  438. evaluation. This environment consists of a dictionary of global variables,
  439. a mapping object of local variables, arrays of arguments, keywords and
  440. defaults, a dictionary of default values for <a class="reference internal" href="../glossary.html#keyword-only-parameter"><span class="std std-ref">keyword-only</span></a> arguments and a closure tuple of cells.</p>
  441. </dd></dl>
  442. <dl class="c function">
  443. <dt class="sig sig-object c" id="c.PyEval_EvalFrame">
  444. <a class="reference internal" href="structures.html#c.PyObject" title="PyObject"><span class="n"><span class="pre">PyObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="sig-name descname"><span class="n"><span class="pre">PyEval_EvalFrame</span></span></span><span class="sig-paren">(</span><a class="reference internal" href="frame.html#c.PyFrameObject" title="PyFrameObject"><span class="n"><span class="pre">PyFrameObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">f</span></span><span class="sig-paren">)</span><a class="headerlink" href="#c.PyEval_EvalFrame" title="Link to this definition">¶</a><br /></dt>
  445. <dd><em class="refcount">Return value: New reference.</em><em class="stableabi"> Part of the <a class="reference internal" href="stable.html#stable"><span class="std std-ref">Stable ABI</span></a>.</em><p>Evaluate an execution frame. This is a simplified interface to
  446. <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>, for backward compatibility.</p>
  447. </dd></dl>
  448. <dl class="c function">
  449. <dt class="sig sig-object c" id="c.PyEval_EvalFrameEx">
  450. <a class="reference internal" href="structures.html#c.PyObject" title="PyObject"><span class="n"><span class="pre">PyObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="sig-name descname"><span class="n"><span class="pre">PyEval_EvalFrameEx</span></span></span><span class="sig-paren">(</span><a class="reference internal" href="frame.html#c.PyFrameObject" title="PyFrameObject"><span class="n"><span class="pre">PyFrameObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">f</span></span>, <span class="kt"><span class="pre">int</span></span><span class="w"> </span><span class="n"><span class="pre">throwflag</span></span><span class="sig-paren">)</span><a class="headerlink" href="#c.PyEval_EvalFrameEx" title="Link to this definition">¶</a><br /></dt>
  451. <dd><em class="refcount">Return value: New reference.</em><em class="stableabi"> Part of the <a class="reference internal" href="stable.html#stable"><span class="std std-ref">Stable ABI</span></a>.</em><p>This is the main, unvarnished function of Python interpretation. The code
  452. object associated with the execution frame <em>f</em> is executed, interpreting
  453. bytecode and executing calls as needed. The additional <em>throwflag</em>
  454. parameter can mostly be ignored - if true, then it causes an exception
  455. to immediately be thrown; this is used for the <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>
  456. methods of generator objects.</p>
  457. <div class="versionchanged">
  458. <p><span class="versionmodified changed">Changed in version 3.4: </span>This function now includes a debug assertion to help ensure that it
  459. does not silently discard an active exception.</p>
  460. </div>
  461. </dd></dl>
  462. <dl class="c function">
  463. <dt class="sig sig-object c" id="c.PyEval_MergeCompilerFlags">
  464. <span class="kt"><span class="pre">int</span></span><span class="w"> </span><span class="sig-name descname"><span class="n"><span class="pre">PyEval_MergeCompilerFlags</span></span></span><span class="sig-paren">(</span><a class="reference internal" href="#c.PyCompilerFlags" title="PyCompilerFlags"><span class="n"><span class="pre">PyCompilerFlags</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">cf</span></span><span class="sig-paren">)</span><a class="headerlink" href="#c.PyEval_MergeCompilerFlags" title="Link to this definition">¶</a><br /></dt>
  465. <dd><p>This function changes the flags of the current evaluation frame, and returns
  466. true on success, false on failure.</p>
  467. </dd></dl>
  468. <dl class="c var">
  469. <dt class="sig sig-object c" id="c.Py_eval_input">
  470. <span class="kt"><span class="pre">int</span></span><span class="w"> </span><span class="sig-name descname"><span class="n"><span class="pre">Py_eval_input</span></span></span><a class="headerlink" href="#c.Py_eval_input" title="Link to this definition">¶</a><br /></dt>
  471. <dd><p id="index-0">The start symbol from the Python grammar for isolated expressions; for use with
  472. <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>
  473. </dd></dl>
  474. <dl class="c var">
  475. <dt class="sig sig-object c" id="c.Py_file_input">
  476. <span class="kt"><span class="pre">int</span></span><span class="w"> </span><span class="sig-name descname"><span class="n"><span class="pre">Py_file_input</span></span></span><a class="headerlink" href="#c.Py_file_input" title="Link to this definition">¶</a><br /></dt>
  477. <dd><p id="index-1">The start symbol from the Python grammar for sequences of statements as read
  478. from a file or other source; for use with <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>. This is
  479. the symbol to use when compiling arbitrarily long Python source code.</p>
  480. </dd></dl>
  481. <dl class="c var">
  482. <dt class="sig sig-object c" id="c.Py_single_input">
  483. <span class="kt"><span class="pre">int</span></span><span class="w"> </span><span class="sig-name descname"><span class="n"><span class="pre">Py_single_input</span></span></span><a class="headerlink" href="#c.Py_single_input" title="Link to this definition">¶</a><br /></dt>
  484. <dd><p id="index-2">The start symbol from the Python grammar for a single statement; for use with
  485. <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>. This is the symbol used for the interactive
  486. interpreter loop.</p>
  487. </dd></dl>
  488. <dl class="c struct">
  489. <dt class="sig sig-object c" id="c.PyCompilerFlags">
  490. <span class="k"><span class="pre">struct</span></span><span class="w"> </span><span class="sig-name descname"><span class="n"><span class="pre">PyCompilerFlags</span></span></span><a class="headerlink" href="#c.PyCompilerFlags" title="Link to this definition">¶</a><br /></dt>
  491. <dd><p>This is the structure used to hold compiler flags. In cases where code is only
  492. being compiled, it is passed as <code class="docutils literal notranslate"><span class="pre">int</span> <span class="pre">flags</span></code>, and in cases where code is being
  493. executed, it is passed as <code class="docutils literal notranslate"><span class="pre">PyCompilerFlags</span> <span class="pre">*flags</span></code>. In this case, <code class="docutils literal notranslate"><span class="pre">from</span>
  494. <span class="pre">__future__</span> <span class="pre">import</span></code> can modify <em>flags</em>.</p>
  495. <p>Whenever <code class="docutils literal notranslate"><span class="pre">PyCompilerFlags</span> <span class="pre">*flags</span></code> is <code class="docutils literal notranslate"><span class="pre">NULL</span></code>, <a class="reference internal" href="#c.PyCompilerFlags.cf_flags" title="PyCompilerFlags.cf_flags"><code class="xref c c-member docutils literal notranslate"><span class="pre">cf_flags</span></code></a> is treated as
  496. equal to <code class="docutils literal notranslate"><span class="pre">0</span></code>, and any modification due to <code class="docutils literal notranslate"><span class="pre">from</span> <span class="pre">__future__</span> <span class="pre">import</span></code> is
  497. discarded.</p>
  498. <dl class="c member">
  499. <dt class="sig sig-object c" id="c.PyCompilerFlags.cf_flags">
  500. <span class="kt"><span class="pre">int</span></span><span class="w"> </span><span class="sig-name descname"><span class="n"><span class="pre">cf_flags</span></span></span><a class="headerlink" href="#c.PyCompilerFlags.cf_flags" title="Link to this definition">¶</a><br /></dt>
  501. <dd><p>Compiler flags.</p>
  502. </dd></dl>
  503. <dl class="c member">
  504. <dt class="sig sig-object c" id="c.PyCompilerFlags.cf_feature_version">
  505. <span class="kt"><span class="pre">int</span></span><span class="w"> </span><span class="sig-name descname"><span class="n"><span class="pre">cf_feature_version</span></span></span><a class="headerlink" href="#c.PyCompilerFlags.cf_feature_version" title="Link to this definition">¶</a><br /></dt>
  506. <dd><p><em>cf_feature_version</em> is the minor Python version. It should be
  507. initialized to <code class="docutils literal notranslate"><span class="pre">PY_MINOR_VERSION</span></code>.</p>
  508. <p>The field is ignored by default, it is used if and only if
  509. <code class="docutils literal notranslate"><span class="pre">PyCF_ONLY_AST</span></code> flag is set in <a class="reference internal" href="#c.PyCompilerFlags.cf_flags" title="PyCompilerFlags.cf_flags"><code class="xref c c-member docutils literal notranslate"><span class="pre">cf_flags</span></code></a>.</p>
  510. </dd></dl>
  511. <div class="versionchanged">
  512. <p><span class="versionmodified changed">Changed in version 3.8: </span>Added <em>cf_feature_version</em> field.</p>
  513. </div>
  514. </dd></dl>
  515. <dl class="c var">
  516. <dt class="sig sig-object c" id="c.CO_FUTURE_DIVISION">
  517. <span class="kt"><span class="pre">int</span></span><span class="w"> </span><span class="sig-name descname"><span class="n"><span class="pre">CO_FUTURE_DIVISION</span></span></span><a class="headerlink" href="#c.CO_FUTURE_DIVISION" title="Link to this definition">¶</a><br /></dt>
  518. <dd><p>This bit can be set in <em>flags</em> to cause division operator <code class="docutils literal notranslate"><span class="pre">/</span></code> to be
  519. interpreted as “true division” according to <span class="target" id="index-3"></span><a class="pep reference external" href="https://peps.python.org/pep-0238/"><strong>PEP 238</strong></a>.</p>
  520. </dd></dl>
  521. </section>
  522. <div class="clearer"></div>
  523. </div>
  524. </div>
  525. </div>
  526. <div class="sphinxsidebar" role="navigation" aria-label="main navigation">
  527. <div class="sphinxsidebarwrapper">
  528. <div>
  529. <h4>Previous topic</h4>
  530. <p class="topless"><a href="stable.html"
  531. title="previous chapter">C API Stability</a></p>
  532. </div>
  533. <div>
  534. <h4>Next topic</h4>
  535. <p class="topless"><a href="refcounting.html"
  536. title="next chapter">Reference Counting</a></p>
  537. </div>
  538. <div role="note" aria-label="source link">
  539. <h3>This Page</h3>
  540. <ul class="this-page-menu">
  541. <li><a href="../bugs.html">Report a Bug</a></li>
  542. <li>
  543. <a href="https://github.com/python/cpython/blob/main/Doc/c-api/veryhigh.rst"
  544. rel="nofollow">Show Source
  545. </a>
  546. </li>
  547. </ul>
  548. </div>
  549. </div>
  550. <div id="sidebarbutton" title="Collapse sidebar">
  551. <span>«</span>
  552. </div>
  553. </div>
  554. <div class="clearer"></div>
  555. </div>
  556. <div class="related" role="navigation" aria-label="related navigation">
  557. <h3>Navigation</h3>
  558. <ul>
  559. <li class="right" style="margin-right: 10px">
  560. <a href="../genindex.html" title="General Index"
  561. >index</a></li>
  562. <li class="right" >
  563. <a href="../py-modindex.html" title="Python Module Index"
  564. >modules</a> |</li>
  565. <li class="right" >
  566. <a href="refcounting.html" title="Reference Counting"
  567. >next</a> |</li>
  568. <li class="right" >
  569. <a href="stable.html" title="C API Stability"
  570. >previous</a> |</li>
  571. <li><img src="../_static/py.svg" alt="Python logo" style="vertical-align: middle; margin-top: -1px"/></li>
  572. <li><a href="https://www.python.org/">Python</a> &#187;</li>
  573. <li class="switchers">
  574. <div class="language_switcher_placeholder"></div>
  575. <div class="version_switcher_placeholder"></div>
  576. </li>
  577. <li>
  578. </li>
  579. <li id="cpython-language-and-version">
  580. <a href="../index.html">3.12.3 Documentation</a> &#187;
  581. </li>
  582. <li class="nav-item nav-item-1"><a href="index.html" >Python/C API Reference Manual</a> &#187;</li>
  583. <li class="nav-item nav-item-this"><a href="">The Very High Level Layer</a></li>
  584. <li class="right">
  585. <div class="inline-search" role="search">
  586. <form class="inline-search" action="../search.html" method="get">
  587. <input placeholder="Quick search" aria-label="Quick search" type="search" name="q" id="search-box" />
  588. <input type="submit" value="Go" />
  589. </form>
  590. </div>
  591. |
  592. </li>
  593. <li class="right">
  594. <label class="theme-selector-label">
  595. Theme
  596. <select class="theme-selector" oninput="activateTheme(this.value)">
  597. <option value="auto" selected>Auto</option>
  598. <option value="light">Light</option>
  599. <option value="dark">Dark</option>
  600. </select>
  601. </label> |</li>
  602. </ul>
  603. </div>
  604. <div class="footer">
  605. &copy;
  606. <a href="../copyright.html">
  607. Copyright
  608. </a>
  609. 2001-2024, Python Software Foundation.
  610. <br />
  611. This page is licensed under the Python Software Foundation License Version 2.
  612. <br />
  613. Examples, recipes, and other code in the documentation are additionally licensed under the Zero Clause BSD License.
  614. <br />
  615. See <a href="/license.html">History and License</a> for more information.<br />
  616. <br />
  617. The Python Software Foundation is a non-profit corporation.
  618. <a href="https://www.python.org/psf/donations/">Please donate.</a>
  619. <br />
  620. <br />
  621. Last updated on Apr 09, 2024 (13:47 UTC).
  622. <a href="/bugs.html">Found a bug</a>?
  623. <br />
  624. Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 7.2.6.
  625. </div>
  626. </body>
  627. </html>
上海开阖软件有限公司 沪ICP备12045867号-1