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.

602 lines
50KB

  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="Extending/Embedding FAQ" />
  7. <meta property="og:type" content="website" />
  8. <meta property="og:url" content="https://docs.python.org/3/faq/extending.html" />
  9. <meta property="og:site_name" content="Python documentation" />
  10. <meta property="og:description" content="Contents: Extending/Embedding FAQ- Can I create my own functions in C?, Can I create my own functions in C++?, Writing C is hard; are there any alternatives?, How can I execute arbitrary Python sta..." />
  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="Contents: Extending/Embedding FAQ- Can I create my own functions in C?, Can I create my own functions in C++?, Writing C is hard; are there any alternatives?, How can I execute arbitrary Python sta..." />
  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>Extending/Embedding FAQ &#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="Python on Windows FAQ" href="windows.html" />
  33. <link rel="prev" title="Library and Extension FAQ" href="library.html" />
  34. <link rel="canonical" href="https://docs.python.org/3/faq/extending.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. <h3><a href="../contents.html">Table of Contents</a></h3>
  84. <ul>
  85. <li><a class="reference internal" href="#">Extending/Embedding FAQ</a><ul>
  86. <li><a class="reference internal" href="#can-i-create-my-own-functions-in-c">Can I create my own functions in C?</a></li>
  87. <li><a class="reference internal" href="#id1">Can I create my own functions in C++?</a></li>
  88. <li><a class="reference internal" href="#writing-c-is-hard-are-there-any-alternatives">Writing C is hard; are there any alternatives?</a></li>
  89. <li><a class="reference internal" href="#how-can-i-execute-arbitrary-python-statements-from-c">How can I execute arbitrary Python statements from C?</a></li>
  90. <li><a class="reference internal" href="#how-can-i-evaluate-an-arbitrary-python-expression-from-c">How can I evaluate an arbitrary Python expression from C?</a></li>
  91. <li><a class="reference internal" href="#how-do-i-extract-c-values-from-a-python-object">How do I extract C values from a Python object?</a></li>
  92. <li><a class="reference internal" href="#how-do-i-use-py-buildvalue-to-create-a-tuple-of-arbitrary-length">How do I use Py_BuildValue() to create a tuple of arbitrary length?</a></li>
  93. <li><a class="reference internal" href="#how-do-i-call-an-object-s-method-from-c">How do I call an object’s method from C?</a></li>
  94. <li><a class="reference internal" href="#how-do-i-catch-the-output-from-pyerr-print-or-anything-that-prints-to-stdout-stderr">How do I catch the output from PyErr_Print() (or anything that prints to stdout/stderr)?</a></li>
  95. <li><a class="reference internal" href="#how-do-i-access-a-module-written-in-python-from-c">How do I access a module written in Python from C?</a></li>
  96. <li><a class="reference internal" href="#how-do-i-interface-to-c-objects-from-python">How do I interface to C++ objects from Python?</a></li>
  97. <li><a class="reference internal" href="#i-added-a-module-using-the-setup-file-and-the-make-fails-why">I added a module using the Setup file and the make fails; why?</a></li>
  98. <li><a class="reference internal" href="#how-do-i-debug-an-extension">How do I debug an extension?</a></li>
  99. <li><a class="reference internal" href="#i-want-to-compile-a-python-module-on-my-linux-system-but-some-files-are-missing-why">I want to compile a Python module on my Linux system, but some files are missing. Why?</a></li>
  100. <li><a class="reference internal" href="#how-do-i-tell-incomplete-input-from-invalid-input">How do I tell “incomplete input” from “invalid input”?</a></li>
  101. <li><a class="reference internal" href="#how-do-i-find-undefined-g-symbols-builtin-new-or-pure-virtual">How do I find undefined g++ symbols __builtin_new or __pure_virtual?</a></li>
  102. <li><a class="reference internal" href="#can-i-create-an-object-class-with-some-methods-implemented-in-c-and-others-in-python-e-g-through-inheritance">Can I create an object class with some methods implemented in C and others in Python (e.g. through inheritance)?</a></li>
  103. </ul>
  104. </li>
  105. </ul>
  106. </div>
  107. <div>
  108. <h4>Previous topic</h4>
  109. <p class="topless"><a href="library.html"
  110. title="previous chapter">Library and Extension FAQ</a></p>
  111. </div>
  112. <div>
  113. <h4>Next topic</h4>
  114. <p class="topless"><a href="windows.html"
  115. title="next chapter">Python on Windows FAQ</a></p>
  116. </div>
  117. <div role="note" aria-label="source link">
  118. <h3>This Page</h3>
  119. <ul class="this-page-menu">
  120. <li><a href="../bugs.html">Report a Bug</a></li>
  121. <li>
  122. <a href="https://github.com/python/cpython/blob/main/Doc/faq/extending.rst"
  123. rel="nofollow">Show Source
  124. </a>
  125. </li>
  126. </ul>
  127. </div>
  128. </nav>
  129. </div>
  130. </div>
  131. <div class="related" role="navigation" aria-label="related navigation">
  132. <h3>Navigation</h3>
  133. <ul>
  134. <li class="right" style="margin-right: 10px">
  135. <a href="../genindex.html" title="General Index"
  136. accesskey="I">index</a></li>
  137. <li class="right" >
  138. <a href="../py-modindex.html" title="Python Module Index"
  139. >modules</a> |</li>
  140. <li class="right" >
  141. <a href="windows.html" title="Python on Windows FAQ"
  142. accesskey="N">next</a> |</li>
  143. <li class="right" >
  144. <a href="library.html" title="Library and Extension FAQ"
  145. accesskey="P">previous</a> |</li>
  146. <li><img src="../_static/py.svg" alt="Python logo" style="vertical-align: middle; margin-top: -1px"/></li>
  147. <li><a href="https://www.python.org/">Python</a> &#187;</li>
  148. <li class="switchers">
  149. <div class="language_switcher_placeholder"></div>
  150. <div class="version_switcher_placeholder"></div>
  151. </li>
  152. <li>
  153. </li>
  154. <li id="cpython-language-and-version">
  155. <a href="../index.html">3.12.3 Documentation</a> &#187;
  156. </li>
  157. <li class="nav-item nav-item-1"><a href="index.html" accesskey="U">Python Frequently Asked Questions</a> &#187;</li>
  158. <li class="nav-item nav-item-this"><a href="">Extending/Embedding FAQ</a></li>
  159. <li class="right">
  160. <div class="inline-search" role="search">
  161. <form class="inline-search" action="../search.html" method="get">
  162. <input placeholder="Quick search" aria-label="Quick search" type="search" name="q" id="search-box" />
  163. <input type="submit" value="Go" />
  164. </form>
  165. </div>
  166. |
  167. </li>
  168. <li class="right">
  169. <label class="theme-selector-label">
  170. Theme
  171. <select class="theme-selector" oninput="activateTheme(this.value)">
  172. <option value="auto" selected>Auto</option>
  173. <option value="light">Light</option>
  174. <option value="dark">Dark</option>
  175. </select>
  176. </label> |</li>
  177. </ul>
  178. </div>
  179. <div class="document">
  180. <div class="documentwrapper">
  181. <div class="bodywrapper">
  182. <div class="body" role="main">
  183. <section id="extending-embedding-faq">
  184. <h1><a class="toc-backref" href="#id2" role="doc-backlink">Extending/Embedding FAQ</a><a class="headerlink" href="#extending-embedding-faq" title="Link to this heading">¶</a></h1>
  185. <nav class="contents" id="contents">
  186. <p class="topic-title">Contents</p>
  187. <ul class="simple">
  188. <li><p><a class="reference internal" href="#extending-embedding-faq" id="id2">Extending/Embedding FAQ</a></p>
  189. <ul>
  190. <li><p><a class="reference internal" href="#can-i-create-my-own-functions-in-c" id="id3">Can I create my own functions in C?</a></p></li>
  191. <li><p><a class="reference internal" href="#id1" id="id4">Can I create my own functions in C++?</a></p></li>
  192. <li><p><a class="reference internal" href="#writing-c-is-hard-are-there-any-alternatives" id="id5">Writing C is hard; are there any alternatives?</a></p></li>
  193. <li><p><a class="reference internal" href="#how-can-i-execute-arbitrary-python-statements-from-c" id="id6">How can I execute arbitrary Python statements from C?</a></p></li>
  194. <li><p><a class="reference internal" href="#how-can-i-evaluate-an-arbitrary-python-expression-from-c" id="id7">How can I evaluate an arbitrary Python expression from C?</a></p></li>
  195. <li><p><a class="reference internal" href="#how-do-i-extract-c-values-from-a-python-object" id="id8">How do I extract C values from a Python object?</a></p></li>
  196. <li><p><a class="reference internal" href="#how-do-i-use-py-buildvalue-to-create-a-tuple-of-arbitrary-length" id="id9">How do I use Py_BuildValue() to create a tuple of arbitrary length?</a></p></li>
  197. <li><p><a class="reference internal" href="#how-do-i-call-an-object-s-method-from-c" id="id10">How do I call an object’s method from C?</a></p></li>
  198. <li><p><a class="reference internal" href="#how-do-i-catch-the-output-from-pyerr-print-or-anything-that-prints-to-stdout-stderr" id="id11">How do I catch the output from PyErr_Print() (or anything that prints to stdout/stderr)?</a></p></li>
  199. <li><p><a class="reference internal" href="#how-do-i-access-a-module-written-in-python-from-c" id="id12">How do I access a module written in Python from C?</a></p></li>
  200. <li><p><a class="reference internal" href="#how-do-i-interface-to-c-objects-from-python" id="id13">How do I interface to C++ objects from Python?</a></p></li>
  201. <li><p><a class="reference internal" href="#i-added-a-module-using-the-setup-file-and-the-make-fails-why" id="id14">I added a module using the Setup file and the make fails; why?</a></p></li>
  202. <li><p><a class="reference internal" href="#how-do-i-debug-an-extension" id="id15">How do I debug an extension?</a></p></li>
  203. <li><p><a class="reference internal" href="#i-want-to-compile-a-python-module-on-my-linux-system-but-some-files-are-missing-why" id="id16">I want to compile a Python module on my Linux system, but some files are missing. Why?</a></p></li>
  204. <li><p><a class="reference internal" href="#how-do-i-tell-incomplete-input-from-invalid-input" id="id17">How do I tell “incomplete input” from “invalid input”?</a></p></li>
  205. <li><p><a class="reference internal" href="#how-do-i-find-undefined-g-symbols-builtin-new-or-pure-virtual" id="id18">How do I find undefined g++ symbols __builtin_new or __pure_virtual?</a></p></li>
  206. <li><p><a class="reference internal" href="#can-i-create-an-object-class-with-some-methods-implemented-in-c-and-others-in-python-e-g-through-inheritance" id="id19">Can I create an object class with some methods implemented in C and others in Python (e.g. through inheritance)?</a></p></li>
  207. </ul>
  208. </li>
  209. </ul>
  210. </nav>
  211. <section id="can-i-create-my-own-functions-in-c">
  212. <h2><a class="toc-backref" href="#id3" role="doc-backlink">Can I create my own functions in C?</a><a class="headerlink" href="#can-i-create-my-own-functions-in-c" title="Link to this heading">¶</a></h2>
  213. <p>Yes, you can create built-in modules containing functions, variables, exceptions
  214. and even new types in C. This is explained in the document
  215. <a class="reference internal" href="../extending/index.html#extending-index"><span class="std std-ref">Extending and Embedding the Python Interpreter</span></a>.</p>
  216. <p>Most intermediate or advanced Python books will also cover this topic.</p>
  217. </section>
  218. <section id="id1">
  219. <h2><a class="toc-backref" href="#id4" role="doc-backlink">Can I create my own functions in C++?</a><a class="headerlink" href="#id1" title="Link to this heading">¶</a></h2>
  220. <p>Yes, using the C compatibility features found in C++. Place <code class="docutils literal notranslate"><span class="pre">extern</span> <span class="pre">&quot;C&quot;</span> <span class="pre">{</span>
  221. <span class="pre">...</span> <span class="pre">}</span></code> around the Python include files and put <code class="docutils literal notranslate"><span class="pre">extern</span> <span class="pre">&quot;C&quot;</span></code> before each
  222. function that is going to be called by the Python interpreter. Global or static
  223. C++ objects with constructors are probably not a good idea.</p>
  224. </section>
  225. <section id="writing-c-is-hard-are-there-any-alternatives">
  226. <span id="c-wrapper-software"></span><h2><a class="toc-backref" href="#id5" role="doc-backlink">Writing C is hard; are there any alternatives?</a><a class="headerlink" href="#writing-c-is-hard-are-there-any-alternatives" title="Link to this heading">¶</a></h2>
  227. <p>There are a number of alternatives to writing your own C extensions, depending
  228. on what you’re trying to do.</p>
  229. <p><a class="reference external" href="https://cython.org">Cython</a> and its relative <a class="reference external" href="https://www.csse.canterbury.ac.nz/greg.ewing/python/Pyrex/">Pyrex</a> are compilers
  230. that accept a slightly modified form of Python and generate the corresponding
  231. C code. Cython and Pyrex make it possible to write an extension without having
  232. to learn Python’s C API.</p>
  233. <p>If you need to interface to some C or C++ library for which no Python extension
  234. currently exists, you can try wrapping the library’s data types and functions
  235. with a tool such as <a class="reference external" href="https://www.swig.org">SWIG</a>. <a class="reference external" href="https://github.com/Python-SIP/sip">SIP</a>, <a class="reference external" href="https://cxx.sourceforge.net/">CXX</a> <a class="reference external" href="https://www.boost.org/libs/python/doc/index.html">Boost</a>, or <a class="reference external" href="https://github.com/scipy/weave">Weave</a> are also
  236. alternatives for wrapping C++ libraries.</p>
  237. </section>
  238. <section id="how-can-i-execute-arbitrary-python-statements-from-c">
  239. <h2><a class="toc-backref" href="#id6" role="doc-backlink">How can I execute arbitrary Python statements from C?</a><a class="headerlink" href="#how-can-i-execute-arbitrary-python-statements-from-c" title="Link to this heading">¶</a></h2>
  240. <p>The highest-level function to do this is <a class="reference internal" href="../c-api/veryhigh.html#c.PyRun_SimpleString" title="PyRun_SimpleString"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyRun_SimpleString()</span></code></a> which takes
  241. a single string argument to be executed in the context of the module
  242. <code class="docutils literal notranslate"><span class="pre">__main__</span></code> and returns <code class="docutils literal notranslate"><span class="pre">0</span></code> for success and <code class="docutils literal notranslate"><span class="pre">-1</span></code> when an exception occurred
  243. (including <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>). If you want more control, use
  244. <a class="reference internal" href="../c-api/veryhigh.html#c.PyRun_String" title="PyRun_String"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyRun_String()</span></code></a>; see the source for <a class="reference internal" href="../c-api/veryhigh.html#c.PyRun_SimpleString" title="PyRun_SimpleString"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyRun_SimpleString()</span></code></a> in
  245. <code class="docutils literal notranslate"><span class="pre">Python/pythonrun.c</span></code>.</p>
  246. </section>
  247. <section id="how-can-i-evaluate-an-arbitrary-python-expression-from-c">
  248. <h2><a class="toc-backref" href="#id7" role="doc-backlink">How can I evaluate an arbitrary Python expression from C?</a><a class="headerlink" href="#how-can-i-evaluate-an-arbitrary-python-expression-from-c" title="Link to this heading">¶</a></h2>
  249. <p>Call the function <a class="reference internal" href="../c-api/veryhigh.html#c.PyRun_String" title="PyRun_String"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyRun_String()</span></code></a> from the previous question with the
  250. start symbol <a class="reference internal" href="../c-api/veryhigh.html#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>; it parses an expression, evaluates it and
  251. returns its value.</p>
  252. </section>
  253. <section id="how-do-i-extract-c-values-from-a-python-object">
  254. <h2><a class="toc-backref" href="#id8" role="doc-backlink">How do I extract C values from a Python object?</a><a class="headerlink" href="#how-do-i-extract-c-values-from-a-python-object" title="Link to this heading">¶</a></h2>
  255. <p>That depends on the object’s type. If it’s a tuple, <a class="reference internal" href="../c-api/tuple.html#c.PyTuple_Size" title="PyTuple_Size"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyTuple_Size()</span></code></a>
  256. returns its length and <a class="reference internal" href="../c-api/tuple.html#c.PyTuple_GetItem" title="PyTuple_GetItem"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyTuple_GetItem()</span></code></a> returns the item at a specified
  257. index. Lists have similar functions, <a class="reference internal" href="../c-api/list.html#c.PyList_Size" title="PyList_Size"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyList_Size()</span></code></a> and
  258. <a class="reference internal" href="../c-api/list.html#c.PyList_GetItem" title="PyList_GetItem"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyList_GetItem()</span></code></a>.</p>
  259. <p>For bytes, <a class="reference internal" href="../c-api/bytes.html#c.PyBytes_Size" title="PyBytes_Size"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyBytes_Size()</span></code></a> returns its length and
  260. <a class="reference internal" href="../c-api/bytes.html#c.PyBytes_AsStringAndSize" title="PyBytes_AsStringAndSize"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyBytes_AsStringAndSize()</span></code></a> provides a pointer to its value and its
  261. length. Note that Python bytes objects may contain null bytes so C’s
  262. <code class="xref c c-func docutils literal notranslate"><span class="pre">strlen()</span></code> should not be used.</p>
  263. <p>To test the type of an object, first make sure it isn’t <code class="docutils literal notranslate"><span class="pre">NULL</span></code>, and then use
  264. <a class="reference internal" href="../c-api/bytes.html#c.PyBytes_Check" title="PyBytes_Check"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyBytes_Check()</span></code></a>, <a class="reference internal" href="../c-api/tuple.html#c.PyTuple_Check" title="PyTuple_Check"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyTuple_Check()</span></code></a>, <a class="reference internal" href="../c-api/list.html#c.PyList_Check" title="PyList_Check"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyList_Check()</span></code></a>, etc.</p>
  265. <p>There is also a high-level API to Python objects which is provided by the
  266. so-called ‘abstract’ interface – read <code class="docutils literal notranslate"><span class="pre">Include/abstract.h</span></code> for further
  267. details. It allows interfacing with any kind of Python sequence using calls
  268. like <a class="reference internal" href="../c-api/sequence.html#c.PySequence_Length" title="PySequence_Length"><code class="xref c c-func docutils literal notranslate"><span class="pre">PySequence_Length()</span></code></a>, <a class="reference internal" href="../c-api/sequence.html#c.PySequence_GetItem" title="PySequence_GetItem"><code class="xref c c-func docutils literal notranslate"><span class="pre">PySequence_GetItem()</span></code></a>, etc. as well
  269. as many other useful protocols such as numbers (<a class="reference internal" href="../c-api/number.html#c.PyNumber_Index" title="PyNumber_Index"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyNumber_Index()</span></code></a> et
  270. al.) and mappings in the PyMapping APIs.</p>
  271. </section>
  272. <section id="how-do-i-use-py-buildvalue-to-create-a-tuple-of-arbitrary-length">
  273. <h2><a class="toc-backref" href="#id9" role="doc-backlink">How do I use Py_BuildValue() to create a tuple of arbitrary length?</a><a class="headerlink" href="#how-do-i-use-py-buildvalue-to-create-a-tuple-of-arbitrary-length" title="Link to this heading">¶</a></h2>
  274. <p>You can’t. Use <a class="reference internal" href="../c-api/tuple.html#c.PyTuple_Pack" title="PyTuple_Pack"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyTuple_Pack()</span></code></a> instead.</p>
  275. </section>
  276. <section id="how-do-i-call-an-object-s-method-from-c">
  277. <h2><a class="toc-backref" href="#id10" role="doc-backlink">How do I call an object’s method from C?</a><a class="headerlink" href="#how-do-i-call-an-object-s-method-from-c" title="Link to this heading">¶</a></h2>
  278. <p>The <a class="reference internal" href="../c-api/call.html#c.PyObject_CallMethod" title="PyObject_CallMethod"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyObject_CallMethod()</span></code></a> function can be used to call an arbitrary
  279. method of an object. The parameters are the object, the name of the method to
  280. call, a format string like that used with <a class="reference internal" href="../c-api/arg.html#c.Py_BuildValue" title="Py_BuildValue"><code class="xref c c-func docutils literal notranslate"><span class="pre">Py_BuildValue()</span></code></a>, and the
  281. argument values:</p>
  282. <div class="highlight-c notranslate"><div class="highlight"><pre><span></span><span class="n">PyObject</span><span class="w"> </span><span class="o">*</span>
  283. <span class="nf">PyObject_CallMethod</span><span class="p">(</span><span class="n">PyObject</span><span class="w"> </span><span class="o">*</span><span class="n">object</span><span class="p">,</span><span class="w"> </span><span class="k">const</span><span class="w"> </span><span class="kt">char</span><span class="w"> </span><span class="o">*</span><span class="n">method_name</span><span class="p">,</span>
  284. <span class="w"> </span><span class="k">const</span><span class="w"> </span><span class="kt">char</span><span class="w"> </span><span class="o">*</span><span class="n">arg_format</span><span class="p">,</span><span class="w"> </span><span class="p">...);</span>
  285. </pre></div>
  286. </div>
  287. <p>This works for any object that has methods – whether built-in or user-defined.
  288. You are responsible for eventually <a class="reference internal" href="../c-api/refcounting.html#c.Py_DECREF" title="Py_DECREF"><code class="xref c c-func docutils literal notranslate"><span class="pre">Py_DECREF()</span></code></a>‘ing the return value.</p>
  289. <p>To call, e.g., a file object’s “seek” method with arguments 10, 0 (assuming the
  290. file object pointer is “f”):</p>
  291. <div class="highlight-c notranslate"><div class="highlight"><pre><span></span><span class="n">res</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">PyObject_CallMethod</span><span class="p">(</span><span class="n">f</span><span class="p">,</span><span class="w"> </span><span class="s">&quot;seek&quot;</span><span class="p">,</span><span class="w"> </span><span class="s">&quot;(ii)&quot;</span><span class="p">,</span><span class="w"> </span><span class="mi">10</span><span class="p">,</span><span class="w"> </span><span class="mi">0</span><span class="p">);</span>
  292. <span class="k">if</span><span class="w"> </span><span class="p">(</span><span class="n">res</span><span class="w"> </span><span class="o">==</span><span class="w"> </span><span class="nb">NULL</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
  293. <span class="w"> </span><span class="p">...</span><span class="w"> </span><span class="n">an</span><span class="w"> </span><span class="n">exception</span><span class="w"> </span><span class="n">occurred</span><span class="w"> </span><span class="p">...</span>
  294. <span class="p">}</span>
  295. <span class="k">else</span><span class="w"> </span><span class="p">{</span>
  296. <span class="w"> </span><span class="n">Py_DECREF</span><span class="p">(</span><span class="n">res</span><span class="p">);</span>
  297. <span class="p">}</span>
  298. </pre></div>
  299. </div>
  300. <p>Note that since <a class="reference internal" href="../c-api/call.html#c.PyObject_CallObject" title="PyObject_CallObject"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyObject_CallObject()</span></code></a> <em>always</em> wants a tuple for the
  301. argument list, to call a function without arguments, pass “()” for the format,
  302. and to call a function with one argument, surround the argument in parentheses,
  303. e.g. “(i)”.</p>
  304. </section>
  305. <section id="how-do-i-catch-the-output-from-pyerr-print-or-anything-that-prints-to-stdout-stderr">
  306. <h2><a class="toc-backref" href="#id11" role="doc-backlink">How do I catch the output from PyErr_Print() (or anything that prints to stdout/stderr)?</a><a class="headerlink" href="#how-do-i-catch-the-output-from-pyerr-print-or-anything-that-prints-to-stdout-stderr" title="Link to this heading">¶</a></h2>
  307. <p>In Python code, define an object that supports the <code class="docutils literal notranslate"><span class="pre">write()</span></code> method. Assign
  308. this object to <a class="reference internal" href="../library/sys.html#sys.stdout" title="sys.stdout"><code class="xref py py-data docutils literal notranslate"><span class="pre">sys.stdout</span></code></a> and <a class="reference internal" href="../library/sys.html#sys.stderr" title="sys.stderr"><code class="xref py py-data docutils literal notranslate"><span class="pre">sys.stderr</span></code></a>. Call print_error, or
  309. just allow the standard traceback mechanism to work. Then, the output will go
  310. wherever your <code class="docutils literal notranslate"><span class="pre">write()</span></code> method sends it.</p>
  311. <p>The easiest way to do this is to use the <a class="reference internal" href="../library/io.html#io.StringIO" title="io.StringIO"><code class="xref py py-class docutils literal notranslate"><span class="pre">io.StringIO</span></code></a> class:</p>
  312. <div class="highlight-pycon notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">import</span> <span class="nn">io</span><span class="o">,</span> <span class="nn">sys</span>
  313. <span class="gp">&gt;&gt;&gt; </span><span class="n">sys</span><span class="o">.</span><span class="n">stdout</span> <span class="o">=</span> <span class="n">io</span><span class="o">.</span><span class="n">StringIO</span><span class="p">()</span>
  314. <span class="gp">&gt;&gt;&gt; </span><span class="nb">print</span><span class="p">(</span><span class="s1">&#39;foo&#39;</span><span class="p">)</span>
  315. <span class="gp">&gt;&gt;&gt; </span><span class="nb">print</span><span class="p">(</span><span class="s1">&#39;hello world!&#39;</span><span class="p">)</span>
  316. <span class="gp">&gt;&gt;&gt; </span><span class="n">sys</span><span class="o">.</span><span class="n">stderr</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="n">sys</span><span class="o">.</span><span class="n">stdout</span><span class="o">.</span><span class="n">getvalue</span><span class="p">())</span>
  317. <span class="go">foo</span>
  318. <span class="go">hello world!</span>
  319. </pre></div>
  320. </div>
  321. <p>A custom object to do the same would look like this:</p>
  322. <div class="highlight-pycon notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">import</span> <span class="nn">io</span><span class="o">,</span> <span class="nn">sys</span>
  323. <span class="gp">&gt;&gt;&gt; </span><span class="k">class</span> <span class="nc">StdoutCatcher</span><span class="p">(</span><span class="n">io</span><span class="o">.</span><span class="n">TextIOBase</span><span class="p">):</span>
  324. <span class="gp">... </span> <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
  325. <span class="gp">... </span> <span class="bp">self</span><span class="o">.</span><span class="n">data</span> <span class="o">=</span> <span class="p">[]</span>
  326. <span class="gp">... </span> <span class="k">def</span> <span class="nf">write</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">stuff</span><span class="p">):</span>
  327. <span class="gp">... </span> <span class="bp">self</span><span class="o">.</span><span class="n">data</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">stuff</span><span class="p">)</span>
  328. <span class="gp">...</span>
  329. <span class="gp">&gt;&gt;&gt; </span><span class="kn">import</span> <span class="nn">sys</span>
  330. <span class="gp">&gt;&gt;&gt; </span><span class="n">sys</span><span class="o">.</span><span class="n">stdout</span> <span class="o">=</span> <span class="n">StdoutCatcher</span><span class="p">()</span>
  331. <span class="gp">&gt;&gt;&gt; </span><span class="nb">print</span><span class="p">(</span><span class="s1">&#39;foo&#39;</span><span class="p">)</span>
  332. <span class="gp">&gt;&gt;&gt; </span><span class="nb">print</span><span class="p">(</span><span class="s1">&#39;hello world!&#39;</span><span class="p">)</span>
  333. <span class="gp">&gt;&gt;&gt; </span><span class="n">sys</span><span class="o">.</span><span class="n">stderr</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s1">&#39;&#39;</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">sys</span><span class="o">.</span><span class="n">stdout</span><span class="o">.</span><span class="n">data</span><span class="p">))</span>
  334. <span class="go">foo</span>
  335. <span class="go">hello world!</span>
  336. </pre></div>
  337. </div>
  338. </section>
  339. <section id="how-do-i-access-a-module-written-in-python-from-c">
  340. <h2><a class="toc-backref" href="#id12" role="doc-backlink">How do I access a module written in Python from C?</a><a class="headerlink" href="#how-do-i-access-a-module-written-in-python-from-c" title="Link to this heading">¶</a></h2>
  341. <p>You can get a pointer to the module object as follows:</p>
  342. <div class="highlight-c notranslate"><div class="highlight"><pre><span></span><span class="n">module</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">PyImport_ImportModule</span><span class="p">(</span><span class="s">&quot;&lt;modulename&gt;&quot;</span><span class="p">);</span>
  343. </pre></div>
  344. </div>
  345. <p>If the module hasn’t been imported yet (i.e. it is not yet present in
  346. <a class="reference internal" href="../library/sys.html#sys.modules" title="sys.modules"><code class="xref py py-data docutils literal notranslate"><span class="pre">sys.modules</span></code></a>), this initializes the module; otherwise it simply returns
  347. the value of <code class="docutils literal notranslate"><span class="pre">sys.modules[&quot;&lt;modulename&gt;&quot;]</span></code>. Note that it doesn’t enter the
  348. module into any namespace – it only ensures it has been initialized and is
  349. stored in <a class="reference internal" href="../library/sys.html#sys.modules" title="sys.modules"><code class="xref py py-data docutils literal notranslate"><span class="pre">sys.modules</span></code></a>.</p>
  350. <p>You can then access the module’s attributes (i.e. any name defined in the
  351. module) as follows:</p>
  352. <div class="highlight-c notranslate"><div class="highlight"><pre><span></span><span class="n">attr</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">PyObject_GetAttrString</span><span class="p">(</span><span class="n">module</span><span class="p">,</span><span class="w"> </span><span class="s">&quot;&lt;attrname&gt;&quot;</span><span class="p">);</span>
  353. </pre></div>
  354. </div>
  355. <p>Calling <a class="reference internal" href="../c-api/object.html#c.PyObject_SetAttrString" title="PyObject_SetAttrString"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyObject_SetAttrString()</span></code></a> to assign to variables in the module
  356. also works.</p>
  357. </section>
  358. <section id="how-do-i-interface-to-c-objects-from-python">
  359. <h2><a class="toc-backref" href="#id13" role="doc-backlink">How do I interface to C++ objects from Python?</a><a class="headerlink" href="#how-do-i-interface-to-c-objects-from-python" title="Link to this heading">¶</a></h2>
  360. <p>Depending on your requirements, there are many approaches. To do this manually,
  361. begin by reading <a class="reference internal" href="../extending/index.html#extending-index"><span class="std std-ref">the “Extending and Embedding” document</span></a>. Realize that for the Python run-time system, there isn’t a
  362. whole lot of difference between C and C++ – so the strategy of building a new
  363. Python type around a C structure (pointer) type will also work for C++ objects.</p>
  364. <p>For C++ libraries, see <a class="reference internal" href="#c-wrapper-software"><span class="std std-ref">Writing C is hard; are there any alternatives?</span></a>.</p>
  365. </section>
  366. <section id="i-added-a-module-using-the-setup-file-and-the-make-fails-why">
  367. <h2><a class="toc-backref" href="#id14" role="doc-backlink">I added a module using the Setup file and the make fails; why?</a><a class="headerlink" href="#i-added-a-module-using-the-setup-file-and-the-make-fails-why" title="Link to this heading">¶</a></h2>
  368. <p>Setup must end in a newline, if there is no newline there, the build process
  369. fails. (Fixing this requires some ugly shell script hackery, and this bug is so
  370. minor that it doesn’t seem worth the effort.)</p>
  371. </section>
  372. <section id="how-do-i-debug-an-extension">
  373. <h2><a class="toc-backref" href="#id15" role="doc-backlink">How do I debug an extension?</a><a class="headerlink" href="#how-do-i-debug-an-extension" title="Link to this heading">¶</a></h2>
  374. <p>When using GDB with dynamically loaded extensions, you can’t set a breakpoint in
  375. your extension until your extension is loaded.</p>
  376. <p>In your <code class="docutils literal notranslate"><span class="pre">.gdbinit</span></code> file (or interactively), add the command:</p>
  377. <div class="highlight-none notranslate"><div class="highlight"><pre><span></span>br _PyImport_LoadDynamicModule
  378. </pre></div>
  379. </div>
  380. <p>Then, when you run GDB:</p>
  381. <div class="highlight-shell-session notranslate"><div class="highlight"><pre><span></span><span class="gp">$ </span>gdb<span class="w"> </span>/local/bin/python
  382. <span class="go">gdb) run myscript.py</span>
  383. <span class="go">gdb) continue # repeat until your extension is loaded</span>
  384. <span class="go">gdb) finish # so that your extension is loaded</span>
  385. <span class="go">gdb) br myfunction.c:50</span>
  386. <span class="go">gdb) continue</span>
  387. </pre></div>
  388. </div>
  389. </section>
  390. <section id="i-want-to-compile-a-python-module-on-my-linux-system-but-some-files-are-missing-why">
  391. <h2><a class="toc-backref" href="#id16" role="doc-backlink">I want to compile a Python module on my Linux system, but some files are missing. Why?</a><a class="headerlink" href="#i-want-to-compile-a-python-module-on-my-linux-system-but-some-files-are-missing-why" title="Link to this heading">¶</a></h2>
  392. <p>Most packaged versions of Python don’t include the
  393. <code class="file docutils literal notranslate"><span class="pre">/usr/lib/python2.</span><em><span class="pre">x</span></em><span class="pre">/config/</span></code> directory, which contains various files
  394. required for compiling Python extensions.</p>
  395. <p>For Red Hat, install the python-devel RPM to get the necessary files.</p>
  396. <p>For Debian, run <code class="docutils literal notranslate"><span class="pre">apt-get</span> <span class="pre">install</span> <span class="pre">python-dev</span></code>.</p>
  397. </section>
  398. <section id="how-do-i-tell-incomplete-input-from-invalid-input">
  399. <h2><a class="toc-backref" href="#id17" role="doc-backlink">How do I tell “incomplete input” from “invalid input”?</a><a class="headerlink" href="#how-do-i-tell-incomplete-input-from-invalid-input" title="Link to this heading">¶</a></h2>
  400. <p>Sometimes you want to emulate the Python interactive interpreter’s behavior,
  401. where it gives you a continuation prompt when the input is incomplete (e.g. you
  402. typed the start of an “if” statement or you didn’t close your parentheses or
  403. triple string quotes), but it gives you a syntax error message immediately when
  404. the input is invalid.</p>
  405. <p>In Python you can use the <a class="reference internal" href="../library/codeop.html#module-codeop" title="codeop: Compile (possibly incomplete) Python code."><code class="xref py py-mod docutils literal notranslate"><span class="pre">codeop</span></code></a> module, which approximates the parser’s
  406. behavior sufficiently. IDLE uses this, for example.</p>
  407. <p>The easiest way to do it in C is to call <a class="reference internal" href="../c-api/veryhigh.html#c.PyRun_InteractiveLoop" title="PyRun_InteractiveLoop"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyRun_InteractiveLoop()</span></code></a> (perhaps
  408. in a separate thread) and let the Python interpreter handle the input for
  409. you. You can also set the <a class="reference internal" href="../c-api/veryhigh.html#c.PyOS_ReadlineFunctionPointer" title="PyOS_ReadlineFunctionPointer"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyOS_ReadlineFunctionPointer()</span></code></a> to point at your
  410. custom input function. See <code class="docutils literal notranslate"><span class="pre">Modules/readline.c</span></code> and <code class="docutils literal notranslate"><span class="pre">Parser/myreadline.c</span></code>
  411. for more hints.</p>
  412. </section>
  413. <section id="how-do-i-find-undefined-g-symbols-builtin-new-or-pure-virtual">
  414. <h2><a class="toc-backref" href="#id18" role="doc-backlink">How do I find undefined g++ symbols __builtin_new or __pure_virtual?</a><a class="headerlink" href="#how-do-i-find-undefined-g-symbols-builtin-new-or-pure-virtual" title="Link to this heading">¶</a></h2>
  415. <p>To dynamically load g++ extension modules, you must recompile Python, relink it
  416. using g++ (change LINKCC in the Python Modules Makefile), and link your
  417. extension module using g++ (e.g., <code class="docutils literal notranslate"><span class="pre">g++</span> <span class="pre">-shared</span> <span class="pre">-o</span> <span class="pre">mymodule.so</span> <span class="pre">mymodule.o</span></code>).</p>
  418. </section>
  419. <section id="can-i-create-an-object-class-with-some-methods-implemented-in-c-and-others-in-python-e-g-through-inheritance">
  420. <h2><a class="toc-backref" href="#id19" role="doc-backlink">Can I create an object class with some methods implemented in C and others in Python (e.g. through inheritance)?</a><a class="headerlink" href="#can-i-create-an-object-class-with-some-methods-implemented-in-c-and-others-in-python-e-g-through-inheritance" title="Link to this heading">¶</a></h2>
  421. <p>Yes, you can inherit from built-in classes such as <a class="reference internal" href="../library/functions.html#int" title="int"><code class="xref py py-class docutils literal notranslate"><span class="pre">int</span></code></a>, <a class="reference internal" href="../library/stdtypes.html#list" title="list"><code class="xref py py-class docutils literal notranslate"><span class="pre">list</span></code></a>,
  422. <a class="reference internal" href="../library/stdtypes.html#dict" title="dict"><code class="xref py py-class docutils literal notranslate"><span class="pre">dict</span></code></a>, etc.</p>
  423. <p>The Boost Python Library (BPL, <a class="reference external" href="https://www.boost.org/libs/python/doc/index.html">https://www.boost.org/libs/python/doc/index.html</a>)
  424. provides a way of doing this from C++ (i.e. you can inherit from an extension
  425. class written in C++ using the BPL).</p>
  426. </section>
  427. </section>
  428. <div class="clearer"></div>
  429. </div>
  430. </div>
  431. </div>
  432. <div class="sphinxsidebar" role="navigation" aria-label="main navigation">
  433. <div class="sphinxsidebarwrapper">
  434. <div>
  435. <h3><a href="../contents.html">Table of Contents</a></h3>
  436. <ul>
  437. <li><a class="reference internal" href="#">Extending/Embedding FAQ</a><ul>
  438. <li><a class="reference internal" href="#can-i-create-my-own-functions-in-c">Can I create my own functions in C?</a></li>
  439. <li><a class="reference internal" href="#id1">Can I create my own functions in C++?</a></li>
  440. <li><a class="reference internal" href="#writing-c-is-hard-are-there-any-alternatives">Writing C is hard; are there any alternatives?</a></li>
  441. <li><a class="reference internal" href="#how-can-i-execute-arbitrary-python-statements-from-c">How can I execute arbitrary Python statements from C?</a></li>
  442. <li><a class="reference internal" href="#how-can-i-evaluate-an-arbitrary-python-expression-from-c">How can I evaluate an arbitrary Python expression from C?</a></li>
  443. <li><a class="reference internal" href="#how-do-i-extract-c-values-from-a-python-object">How do I extract C values from a Python object?</a></li>
  444. <li><a class="reference internal" href="#how-do-i-use-py-buildvalue-to-create-a-tuple-of-arbitrary-length">How do I use Py_BuildValue() to create a tuple of arbitrary length?</a></li>
  445. <li><a class="reference internal" href="#how-do-i-call-an-object-s-method-from-c">How do I call an object’s method from C?</a></li>
  446. <li><a class="reference internal" href="#how-do-i-catch-the-output-from-pyerr-print-or-anything-that-prints-to-stdout-stderr">How do I catch the output from PyErr_Print() (or anything that prints to stdout/stderr)?</a></li>
  447. <li><a class="reference internal" href="#how-do-i-access-a-module-written-in-python-from-c">How do I access a module written in Python from C?</a></li>
  448. <li><a class="reference internal" href="#how-do-i-interface-to-c-objects-from-python">How do I interface to C++ objects from Python?</a></li>
  449. <li><a class="reference internal" href="#i-added-a-module-using-the-setup-file-and-the-make-fails-why">I added a module using the Setup file and the make fails; why?</a></li>
  450. <li><a class="reference internal" href="#how-do-i-debug-an-extension">How do I debug an extension?</a></li>
  451. <li><a class="reference internal" href="#i-want-to-compile-a-python-module-on-my-linux-system-but-some-files-are-missing-why">I want to compile a Python module on my Linux system, but some files are missing. Why?</a></li>
  452. <li><a class="reference internal" href="#how-do-i-tell-incomplete-input-from-invalid-input">How do I tell “incomplete input” from “invalid input”?</a></li>
  453. <li><a class="reference internal" href="#how-do-i-find-undefined-g-symbols-builtin-new-or-pure-virtual">How do I find undefined g++ symbols __builtin_new or __pure_virtual?</a></li>
  454. <li><a class="reference internal" href="#can-i-create-an-object-class-with-some-methods-implemented-in-c-and-others-in-python-e-g-through-inheritance">Can I create an object class with some methods implemented in C and others in Python (e.g. through inheritance)?</a></li>
  455. </ul>
  456. </li>
  457. </ul>
  458. </div>
  459. <div>
  460. <h4>Previous topic</h4>
  461. <p class="topless"><a href="library.html"
  462. title="previous chapter">Library and Extension FAQ</a></p>
  463. </div>
  464. <div>
  465. <h4>Next topic</h4>
  466. <p class="topless"><a href="windows.html"
  467. title="next chapter">Python on Windows FAQ</a></p>
  468. </div>
  469. <div role="note" aria-label="source link">
  470. <h3>This Page</h3>
  471. <ul class="this-page-menu">
  472. <li><a href="../bugs.html">Report a Bug</a></li>
  473. <li>
  474. <a href="https://github.com/python/cpython/blob/main/Doc/faq/extending.rst"
  475. rel="nofollow">Show Source
  476. </a>
  477. </li>
  478. </ul>
  479. </div>
  480. </div>
  481. <div id="sidebarbutton" title="Collapse sidebar">
  482. <span>«</span>
  483. </div>
  484. </div>
  485. <div class="clearer"></div>
  486. </div>
  487. <div class="related" role="navigation" aria-label="related navigation">
  488. <h3>Navigation</h3>
  489. <ul>
  490. <li class="right" style="margin-right: 10px">
  491. <a href="../genindex.html" title="General Index"
  492. >index</a></li>
  493. <li class="right" >
  494. <a href="../py-modindex.html" title="Python Module Index"
  495. >modules</a> |</li>
  496. <li class="right" >
  497. <a href="windows.html" title="Python on Windows FAQ"
  498. >next</a> |</li>
  499. <li class="right" >
  500. <a href="library.html" title="Library and Extension FAQ"
  501. >previous</a> |</li>
  502. <li><img src="../_static/py.svg" alt="Python logo" style="vertical-align: middle; margin-top: -1px"/></li>
  503. <li><a href="https://www.python.org/">Python</a> &#187;</li>
  504. <li class="switchers">
  505. <div class="language_switcher_placeholder"></div>
  506. <div class="version_switcher_placeholder"></div>
  507. </li>
  508. <li>
  509. </li>
  510. <li id="cpython-language-and-version">
  511. <a href="../index.html">3.12.3 Documentation</a> &#187;
  512. </li>
  513. <li class="nav-item nav-item-1"><a href="index.html" >Python Frequently Asked Questions</a> &#187;</li>
  514. <li class="nav-item nav-item-this"><a href="">Extending/Embedding FAQ</a></li>
  515. <li class="right">
  516. <div class="inline-search" role="search">
  517. <form class="inline-search" action="../search.html" method="get">
  518. <input placeholder="Quick search" aria-label="Quick search" type="search" name="q" id="search-box" />
  519. <input type="submit" value="Go" />
  520. </form>
  521. </div>
  522. |
  523. </li>
  524. <li class="right">
  525. <label class="theme-selector-label">
  526. Theme
  527. <select class="theme-selector" oninput="activateTheme(this.value)">
  528. <option value="auto" selected>Auto</option>
  529. <option value="light">Light</option>
  530. <option value="dark">Dark</option>
  531. </select>
  532. </label> |</li>
  533. </ul>
  534. </div>
  535. <div class="footer">
  536. &copy;
  537. <a href="../copyright.html">
  538. Copyright
  539. </a>
  540. 2001-2024, Python Software Foundation.
  541. <br />
  542. This page is licensed under the Python Software Foundation License Version 2.
  543. <br />
  544. Examples, recipes, and other code in the documentation are additionally licensed under the Zero Clause BSD License.
  545. <br />
  546. See <a href="/license.html">History and License</a> for more information.<br />
  547. <br />
  548. The Python Software Foundation is a non-profit corporation.
  549. <a href="https://www.python.org/psf/donations/">Please donate.</a>
  550. <br />
  551. <br />
  552. Last updated on Apr 09, 2024 (13:47 UTC).
  553. <a href="/bugs.html">Found a bug</a>?
  554. <br />
  555. Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 7.2.6.
  556. </div>
  557. </body>
  558. </html>
上海开阖软件有限公司 沪ICP备12045867号-1