Removed the Requirement to Install Python and NodeJS (Now Bundled with Borealis)

This commit is contained in:
2025-04-24 00:42:19 -06:00
parent 785265d3e7
commit 9c68cdea84
7786 changed files with 2386458 additions and 217 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,604 @@
<!DOCTYPE html>
<html lang="en" data-content_root="../">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="viewport" content="width=device-width, initial-scale=1" />
<meta property="og:title" content="Extending/Embedding FAQ" />
<meta property="og:type" content="website" />
<meta property="og:url" content="https://docs.python.org/3/faq/extending.html" />
<meta property="og:site_name" content="Python documentation" />
<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..." />
<meta property="og:image" content="https://docs.python.org/3/_static/og-image.png" />
<meta property="og:image:alt" content="Python documentation" />
<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..." />
<meta property="og:image:width" content="200">
<meta property="og:image:height" content="200">
<meta name="theme-color" content="#3776ab">
<title>Extending/Embedding FAQ &#8212; Python 3.13.3 documentation</title><meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" type="text/css" href="../_static/pygments.css?v=b86133f3" />
<link rel="stylesheet" type="text/css" href="../_static/pydoctheme.css?v=23252803" />
<link id="pygments_dark_css" media="(prefers-color-scheme: dark)" rel="stylesheet" type="text/css" href="../_static/pygments_dark.css?v=5349f25f" />
<script src="../_static/documentation_options.js?v=5d57ca2d"></script>
<script src="../_static/doctools.js?v=9bcbadda"></script>
<script src="../_static/sphinx_highlight.js?v=dc90522c"></script>
<script src="../_static/sidebar.js"></script>
<link rel="search" type="application/opensearchdescription+xml"
title="Search within Python 3.13.3 documentation"
href="../_static/opensearch.xml"/>
<link rel="author" title="About these documents" href="../about.html" />
<link rel="index" title="Index" href="../genindex.html" />
<link rel="search" title="Search" href="../search.html" />
<link rel="copyright" title="Copyright" href="../copyright.html" />
<link rel="next" title="Python on Windows FAQ" href="windows.html" />
<link rel="prev" title="Library and Extension FAQ" href="library.html" />
<link rel="canonical" href="https://docs.python.org/3/faq/extending.html">
<style>
@media only screen {
table.full-width-table {
width: 100%;
}
}
</style>
<link rel="stylesheet" href="../_static/pydoctheme_dark.css" media="(prefers-color-scheme: dark)" id="pydoctheme_dark_css">
<link rel="shortcut icon" type="image/png" href="../_static/py.svg" />
<script type="text/javascript" src="../_static/copybutton.js"></script>
<script type="text/javascript" src="../_static/menu.js"></script>
<script type="text/javascript" src="../_static/search-focus.js"></script>
<script type="text/javascript" src="../_static/themetoggle.js"></script>
<script type="text/javascript" src="../_static/rtd_switcher.js"></script>
<meta name="readthedocs-addons-api-version" content="1">
</head>
<body>
<div class="mobile-nav">
<input type="checkbox" id="menuToggler" class="toggler__input" aria-controls="navigation"
aria-pressed="false" aria-expanded="false" role="button" aria-label="Menu" />
<nav class="nav-content" role="navigation">
<label for="menuToggler" class="toggler__label">
<span></span>
</label>
<span class="nav-items-wrapper">
<a href="https://www.python.org/" class="nav-logo">
<img src="../_static/py.svg" alt="Python logo"/>
</a>
<span class="version_switcher_placeholder"></span>
<form role="search" class="search" action="../search.html" method="get">
<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" class="search-icon">
<path fill-rule="nonzero" 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>
</svg>
<input placeholder="Quick search" aria-label="Quick search" type="search" name="q" />
<input type="submit" value="Go"/>
</form>
</span>
</nav>
<div class="menu-wrapper">
<nav class="menu" role="navigation" aria-label="main navigation">
<div class="language_switcher_placeholder"></div>
<label class="theme-selector-label">
Theme
<select class="theme-selector" oninput="activateTheme(this.value)">
<option value="auto" selected>Auto</option>
<option value="light">Light</option>
<option value="dark">Dark</option>
</select>
</label>
<div>
<h3><a href="../contents.html">Table of Contents</a></h3>
<ul>
<li><a class="reference internal" href="#">Extending/Embedding FAQ</a><ul>
<li><a class="reference internal" href="#can-i-create-my-own-functions-in-c">Can I create my own functions in C?</a></li>
<li><a class="reference internal" href="#id1">Can I create my own functions in C++?</a></li>
<li><a class="reference internal" href="#writing-c-is-hard-are-there-any-alternatives">Writing C is hard; are there any alternatives?</a></li>
<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>
<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>
<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>
<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>
<li><a class="reference internal" href="#how-do-i-call-an-object-s-method-from-c">How do I call an objects method from C?</a></li>
<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>
<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>
<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>
<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>
<li><a class="reference internal" href="#how-do-i-debug-an-extension">How do I debug an extension?</a></li>
<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>
<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>
<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>
<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>
</ul>
</li>
</ul>
</div>
<div>
<h4>Previous topic</h4>
<p class="topless"><a href="library.html"
title="previous chapter">Library and Extension FAQ</a></p>
</div>
<div>
<h4>Next topic</h4>
<p class="topless"><a href="windows.html"
title="next chapter">Python on Windows FAQ</a></p>
</div>
<div role="note" aria-label="source link">
<h3>This Page</h3>
<ul class="this-page-menu">
<li><a href="../bugs.html">Report a Bug</a></li>
<li>
<a href="https://github.com/python/cpython/blob/main/Doc/faq/extending.rst"
rel="nofollow">Show Source
</a>
</li>
</ul>
</div>
</nav>
</div>
</div>
<div class="related" role="navigation" aria-label="Related">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="../genindex.html" title="General Index"
accesskey="I">index</a></li>
<li class="right" >
<a href="../py-modindex.html" title="Python Module Index"
>modules</a> |</li>
<li class="right" >
<a href="windows.html" title="Python on Windows FAQ"
accesskey="N">next</a> |</li>
<li class="right" >
<a href="library.html" title="Library and Extension FAQ"
accesskey="P">previous</a> |</li>
<li><img src="../_static/py.svg" alt="Python logo" style="vertical-align: middle; margin-top: -1px"/></li>
<li><a href="https://www.python.org/">Python</a> &#187;</li>
<li class="switchers">
<div class="language_switcher_placeholder"></div>
<div class="version_switcher_placeholder"></div>
</li>
<li>
</li>
<li id="cpython-language-and-version">
<a href="../index.html">3.13.3 Documentation</a> &#187;
</li>
<li class="nav-item nav-item-1"><a href="index.html" accesskey="U">Python Frequently Asked Questions</a> &#187;</li>
<li class="nav-item nav-item-this"><a href="">Extending/Embedding FAQ</a></li>
<li class="right">
<div class="inline-search" role="search">
<form class="inline-search" action="../search.html" method="get">
<input placeholder="Quick search" aria-label="Quick search" type="search" name="q" id="search-box" />
<input type="submit" value="Go" />
</form>
</div>
|
</li>
<li class="right">
<label class="theme-selector-label">
Theme
<select class="theme-selector" oninput="activateTheme(this.value)">
<option value="auto" selected>Auto</option>
<option value="light">Light</option>
<option value="dark">Dark</option>
</select>
</label> |</li>
</ul>
</div>
<div class="document">
<div class="documentwrapper">
<div class="bodywrapper">
<div class="body" role="main">
<section id="extending-embedding-faq">
<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>
<nav class="contents" id="contents">
<p class="topic-title">Contents</p>
<ul class="simple">
<li><p><a class="reference internal" href="#extending-embedding-faq" id="id2">Extending/Embedding FAQ</a></p>
<ul>
<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>
<li><p><a class="reference internal" href="#id1" id="id4">Can I create my own functions in C++?</a></p></li>
<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>
<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>
<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>
<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>
<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>
<li><p><a class="reference internal" href="#how-do-i-call-an-object-s-method-from-c" id="id10">How do I call an objects method from C?</a></p></li>
<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>
<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>
<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>
<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>
<li><p><a class="reference internal" href="#how-do-i-debug-an-extension" id="id15">How do I debug an extension?</a></p></li>
<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>
<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>
<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>
<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>
</ul>
</li>
</ul>
</nav>
<section id="can-i-create-my-own-functions-in-c">
<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>
<p>Yes, you can create built-in modules containing functions, variables, exceptions
and even new types in C. This is explained in the document
<a class="reference internal" href="../extending/index.html#extending-index"><span class="std std-ref">Extending and Embedding the Python Interpreter</span></a>.</p>
<p>Most intermediate or advanced Python books will also cover this topic.</p>
</section>
<section id="id1">
<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>
<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>
<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
function that is going to be called by the Python interpreter. Global or static
C++ objects with constructors are probably not a good idea.</p>
</section>
<section id="writing-c-is-hard-are-there-any-alternatives">
<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>
<p>There are a number of alternatives to writing your own C extensions, depending
on what youre trying to do.</p>
<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
that accept a slightly modified form of Python and generate the corresponding
C code. Cython and Pyrex make it possible to write an extension without having
to learn Pythons C API.</p>
<p>If you need to interface to some C or C++ library for which no Python extension
currently exists, you can try wrapping the librarys data types and functions
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
alternatives for wrapping C++ libraries.</p>
</section>
<section id="how-can-i-execute-arbitrary-python-statements-from-c">
<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>
<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
a single string argument to be executed in the context of the module
<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
(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
<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
<code class="docutils literal notranslate"><span class="pre">Python/pythonrun.c</span></code>.</p>
</section>
<section id="how-can-i-evaluate-an-arbitrary-python-expression-from-c">
<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>
<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
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
returns its value.</p>
</section>
<section id="how-do-i-extract-c-values-from-a-python-object">
<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>
<p>That depends on the objects type. If its 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>
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
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
<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>
<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
<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
length. Note that Python bytes objects may contain null bytes so Cs
<code class="xref c c-func docutils literal notranslate"><span class="pre">strlen()</span></code> should not be used.</p>
<p>To test the type of an object, first make sure it isnt <code class="docutils literal notranslate"><span class="pre">NULL</span></code>, and then use
<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>
<p>There is also a high-level API to Python objects which is provided by the
so-called abstract interface read <code class="docutils literal notranslate"><span class="pre">Include/abstract.h</span></code> for further
details. It allows interfacing with any kind of Python sequence using calls
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
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
al.) and mappings in the PyMapping APIs.</p>
</section>
<section id="how-do-i-use-py-buildvalue-to-create-a-tuple-of-arbitrary-length">
<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>
<p>You cant. 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>
</section>
<section id="how-do-i-call-an-object-s-method-from-c">
<h2><a class="toc-backref" href="#id10" role="doc-backlink">How do I call an objects 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>
<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
method of an object. The parameters are the object, the name of the method to
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
argument values:</p>
<div class="highlight-c notranslate"><div class="highlight"><pre><span></span><span class="n">PyObject</span><span class="w"> </span><span class="o">*</span>
<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>
<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>
</pre></div>
</div>
<p>This works for any object that has methods whether built-in or user-defined.
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>
<p>To call, e.g., a file objects “seek” method with arguments 10, 0 (assuming the
file object pointer is “f”):</p>
<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>
<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>
<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>
<span class="p">}</span>
<span class="k">else</span><span class="w"> </span><span class="p">{</span>
<span class="w"> </span><span class="n">Py_DECREF</span><span class="p">(</span><span class="n">res</span><span class="p">);</span>
<span class="p">}</span>
</pre></div>
</div>
<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
argument list, to call a function without arguments, pass “()” for the format,
and to call a function with one argument, surround the argument in parentheses,
e.g. “(i)”.</p>
</section>
<section id="how-do-i-catch-the-output-from-pyerr-print-or-anything-that-prints-to-stdout-stderr">
<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>
<p>In Python code, define an object that supports the <code class="docutils literal notranslate"><span class="pre">write()</span></code> method. Assign
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
just allow the standard traceback mechanism to work. Then, the output will go
wherever your <code class="docutils literal notranslate"><span class="pre">write()</span></code> method sends it.</p>
<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>
<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="w"> </span><span class="nn">io</span><span class="o">,</span><span class="w"> </span><span class="nn">sys</span>
<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>
<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>
<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>
<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>
<span class="go">foo</span>
<span class="go">hello world!</span>
</pre></div>
</div>
<p>A custom object to do the same would look like this:</p>
<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="w"> </span><span class="nn">io</span><span class="o">,</span><span class="w"> </span><span class="nn">sys</span>
<span class="gp">&gt;&gt;&gt; </span><span class="k">class</span><span class="w"> </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>
<span class="gp">... </span> <span class="k">def</span><span class="w"> </span><span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<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>
<span class="gp">... </span> <span class="k">def</span><span class="w"> </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>
<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>
<span class="gp">...</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">import</span><span class="w"> </span><span class="nn">sys</span>
<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>
<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>
<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>
<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>
<span class="go">foo</span>
<span class="go">hello world!</span>
</pre></div>
</div>
</section>
<section id="how-do-i-access-a-module-written-in-python-from-c">
<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>
<p>You can get a pointer to the module object as follows:</p>
<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>
</pre></div>
</div>
<p>If the module hasnt been imported yet (i.e. it is not yet present 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>), this initializes the module; otherwise it simply returns
the value of <code class="docutils literal notranslate"><span class="pre">sys.modules[&quot;&lt;modulename&gt;&quot;]</span></code>. Note that it doesnt enter the
module into any namespace it only ensures it has been initialized and is
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>
<p>You can then access the modules attributes (i.e. any name defined in the
module) as follows:</p>
<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>
</pre></div>
</div>
<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
also works.</p>
</section>
<section id="how-do-i-interface-to-c-objects-from-python">
<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>
<p>Depending on your requirements, there are many approaches. To do this manually,
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 isnt a
whole lot of difference between C and C++ so the strategy of building a new
Python type around a C structure (pointer) type will also work for C++ objects.</p>
<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>
</section>
<section id="i-added-a-module-using-the-setup-file-and-the-make-fails-why">
<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>
<p>Setup must end in a newline, if there is no newline there, the build process
fails. (Fixing this requires some ugly shell script hackery, and this bug is so
minor that it doesnt seem worth the effort.)</p>
</section>
<section id="how-do-i-debug-an-extension">
<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>
<p>When using GDB with dynamically loaded extensions, you cant set a breakpoint in
your extension until your extension is loaded.</p>
<p>In your <code class="docutils literal notranslate"><span class="pre">.gdbinit</span></code> file (or interactively), add the command:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>br _PyImport_LoadDynamicModule
</pre></div>
</div>
<p>Then, when you run GDB:</p>
<div class="highlight-shell-session notranslate"><div class="highlight"><pre><span></span><span class="gp">$ </span>gdb<span class="w"> </span>/local/bin/python
<span class="go">gdb) run myscript.py</span>
<span class="go">gdb) continue # repeat until your extension is loaded</span>
<span class="go">gdb) finish # so that your extension is loaded</span>
<span class="go">gdb) br myfunction.c:50</span>
<span class="go">gdb) continue</span>
</pre></div>
</div>
</section>
<section id="i-want-to-compile-a-python-module-on-my-linux-system-but-some-files-are-missing-why">
<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>
<p>Most packaged versions of Python omit some files
required for compiling Python extensions.</p>
<p>For Red Hat, install the python3-devel RPM to get the necessary files.</p>
<p>For Debian, run <code class="docutils literal notranslate"><span class="pre">apt-get</span> <span class="pre">install</span> <span class="pre">python3-dev</span></code>.</p>
</section>
<section id="how-do-i-tell-incomplete-input-from-invalid-input">
<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>
<p>Sometimes you want to emulate the Python interactive interpreters behavior,
where it gives you a continuation prompt when the input is incomplete (e.g. you
typed the start of an “if” statement or you didnt close your parentheses or
triple string quotes), but it gives you a syntax error message immediately when
the input is invalid.</p>
<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 parsers
behavior sufficiently. IDLE uses this, for example.</p>
<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
in a separate thread) and let the Python interpreter handle the input for
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
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>
for more hints.</p>
</section>
<section id="how-do-i-find-undefined-g-symbols-builtin-new-or-pure-virtual">
<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>
<p>To dynamically load g++ extension modules, you must recompile Python, relink it
using g++ (change LINKCC in the Python Modules Makefile), and link your
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>
</section>
<section id="can-i-create-an-object-class-with-some-methods-implemented-in-c-and-others-in-python-e-g-through-inheritance">
<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>
<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>,
<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>
<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>)
provides a way of doing this from C++ (i.e. you can inherit from an extension
class written in C++ using the BPL).</p>
</section>
</section>
<div class="clearer"></div>
</div>
</div>
</div>
<div class="sphinxsidebar" role="navigation" aria-label="Main">
<div class="sphinxsidebarwrapper">
<div>
<h3><a href="../contents.html">Table of Contents</a></h3>
<ul>
<li><a class="reference internal" href="#">Extending/Embedding FAQ</a><ul>
<li><a class="reference internal" href="#can-i-create-my-own-functions-in-c">Can I create my own functions in C?</a></li>
<li><a class="reference internal" href="#id1">Can I create my own functions in C++?</a></li>
<li><a class="reference internal" href="#writing-c-is-hard-are-there-any-alternatives">Writing C is hard; are there any alternatives?</a></li>
<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>
<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>
<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>
<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>
<li><a class="reference internal" href="#how-do-i-call-an-object-s-method-from-c">How do I call an objects method from C?</a></li>
<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>
<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>
<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>
<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>
<li><a class="reference internal" href="#how-do-i-debug-an-extension">How do I debug an extension?</a></li>
<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>
<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>
<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>
<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>
</ul>
</li>
</ul>
</div>
<div>
<h4>Previous topic</h4>
<p class="topless"><a href="library.html"
title="previous chapter">Library and Extension FAQ</a></p>
</div>
<div>
<h4>Next topic</h4>
<p class="topless"><a href="windows.html"
title="next chapter">Python on Windows FAQ</a></p>
</div>
<div role="note" aria-label="source link">
<h3>This Page</h3>
<ul class="this-page-menu">
<li><a href="../bugs.html">Report a Bug</a></li>
<li>
<a href="https://github.com/python/cpython/blob/main/Doc/faq/extending.rst"
rel="nofollow">Show Source
</a>
</li>
</ul>
</div>
</div>
<div id="sidebarbutton" title="Collapse sidebar">
<span>«</span>
</div>
</div>
<div class="clearer"></div>
</div>
<div class="related" role="navigation" aria-label="Related">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="../genindex.html" title="General Index"
>index</a></li>
<li class="right" >
<a href="../py-modindex.html" title="Python Module Index"
>modules</a> |</li>
<li class="right" >
<a href="windows.html" title="Python on Windows FAQ"
>next</a> |</li>
<li class="right" >
<a href="library.html" title="Library and Extension FAQ"
>previous</a> |</li>
<li><img src="../_static/py.svg" alt="Python logo" style="vertical-align: middle; margin-top: -1px"/></li>
<li><a href="https://www.python.org/">Python</a> &#187;</li>
<li class="switchers">
<div class="language_switcher_placeholder"></div>
<div class="version_switcher_placeholder"></div>
</li>
<li>
</li>
<li id="cpython-language-and-version">
<a href="../index.html">3.13.3 Documentation</a> &#187;
</li>
<li class="nav-item nav-item-1"><a href="index.html" >Python Frequently Asked Questions</a> &#187;</li>
<li class="nav-item nav-item-this"><a href="">Extending/Embedding FAQ</a></li>
<li class="right">
<div class="inline-search" role="search">
<form class="inline-search" action="../search.html" method="get">
<input placeholder="Quick search" aria-label="Quick search" type="search" name="q" id="search-box" />
<input type="submit" value="Go" />
</form>
</div>
|
</li>
<li class="right">
<label class="theme-selector-label">
Theme
<select class="theme-selector" oninput="activateTheme(this.value)">
<option value="auto" selected>Auto</option>
<option value="light">Light</option>
<option value="dark">Dark</option>
</select>
</label> |</li>
</ul>
</div>
<div class="footer">
&copy;
<a href="../copyright.html">
Copyright
</a>
2001-2025, Python Software Foundation.
<br />
This page is licensed under the Python Software Foundation License Version 2.
<br />
Examples, recipes, and other code in the documentation are additionally licensed under the Zero Clause BSD License.
<br />
See <a href="/license.html">History and License</a> for more information.<br />
<br />
The Python Software Foundation is a non-profit corporation.
<a href="https://www.python.org/psf/donations/">Please donate.</a>
<br />
<br />
Last updated on Apr 08, 2025 (14:33 UTC).
<a href="/bugs.html">Found a bug</a>?
<br />
Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 8.2.3.
</div>
</body>
</html>

View File

@@ -0,0 +1,718 @@
<!DOCTYPE html>
<html lang="en" data-content_root="../">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="viewport" content="width=device-width, initial-scale=1" />
<meta property="og:title" content="General Python FAQ" />
<meta property="og:type" content="website" />
<meta property="og:url" content="https://docs.python.org/3/faq/general.html" />
<meta property="og:site_name" content="Python documentation" />
<meta property="og:description" content="Contents: General Python FAQ- General Information- What is Python?, What is the Python Software Foundation?, Are there copyright restrictions on the use of Python?, Why was Python created in the fi..." />
<meta property="og:image" content="https://docs.python.org/3/_static/og-image.png" />
<meta property="og:image:alt" content="Python documentation" />
<meta name="description" content="Contents: General Python FAQ- General Information- What is Python?, What is the Python Software Foundation?, Are there copyright restrictions on the use of Python?, Why was Python created in the fi..." />
<meta property="og:image:width" content="200">
<meta property="og:image:height" content="200">
<meta name="theme-color" content="#3776ab">
<title>General Python FAQ &#8212; Python 3.13.3 documentation</title><meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" type="text/css" href="../_static/pygments.css?v=b86133f3" />
<link rel="stylesheet" type="text/css" href="../_static/pydoctheme.css?v=23252803" />
<link id="pygments_dark_css" media="(prefers-color-scheme: dark)" rel="stylesheet" type="text/css" href="../_static/pygments_dark.css?v=5349f25f" />
<script src="../_static/documentation_options.js?v=5d57ca2d"></script>
<script src="../_static/doctools.js?v=9bcbadda"></script>
<script src="../_static/sphinx_highlight.js?v=dc90522c"></script>
<script src="../_static/sidebar.js"></script>
<link rel="search" type="application/opensearchdescription+xml"
title="Search within Python 3.13.3 documentation"
href="../_static/opensearch.xml"/>
<link rel="author" title="About these documents" href="../about.html" />
<link rel="index" title="Index" href="../genindex.html" />
<link rel="search" title="Search" href="../search.html" />
<link rel="copyright" title="Copyright" href="../copyright.html" />
<link rel="next" title="Programming FAQ" href="programming.html" />
<link rel="prev" title="Python Frequently Asked Questions" href="index.html" />
<link rel="canonical" href="https://docs.python.org/3/faq/general.html">
<style>
@media only screen {
table.full-width-table {
width: 100%;
}
}
</style>
<link rel="stylesheet" href="../_static/pydoctheme_dark.css" media="(prefers-color-scheme: dark)" id="pydoctheme_dark_css">
<link rel="shortcut icon" type="image/png" href="../_static/py.svg" />
<script type="text/javascript" src="../_static/copybutton.js"></script>
<script type="text/javascript" src="../_static/menu.js"></script>
<script type="text/javascript" src="../_static/search-focus.js"></script>
<script type="text/javascript" src="../_static/themetoggle.js"></script>
<script type="text/javascript" src="../_static/rtd_switcher.js"></script>
<meta name="readthedocs-addons-api-version" content="1">
</head>
<body>
<div class="mobile-nav">
<input type="checkbox" id="menuToggler" class="toggler__input" aria-controls="navigation"
aria-pressed="false" aria-expanded="false" role="button" aria-label="Menu" />
<nav class="nav-content" role="navigation">
<label for="menuToggler" class="toggler__label">
<span></span>
</label>
<span class="nav-items-wrapper">
<a href="https://www.python.org/" class="nav-logo">
<img src="../_static/py.svg" alt="Python logo"/>
</a>
<span class="version_switcher_placeholder"></span>
<form role="search" class="search" action="../search.html" method="get">
<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" class="search-icon">
<path fill-rule="nonzero" 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>
</svg>
<input placeholder="Quick search" aria-label="Quick search" type="search" name="q" />
<input type="submit" value="Go"/>
</form>
</span>
</nav>
<div class="menu-wrapper">
<nav class="menu" role="navigation" aria-label="main navigation">
<div class="language_switcher_placeholder"></div>
<label class="theme-selector-label">
Theme
<select class="theme-selector" oninput="activateTheme(this.value)">
<option value="auto" selected>Auto</option>
<option value="light">Light</option>
<option value="dark">Dark</option>
</select>
</label>
<div>
<h3><a href="../contents.html">Table of Contents</a></h3>
<ul>
<li><a class="reference internal" href="#">General Python FAQ</a><ul>
<li><a class="reference internal" href="#general-information">General Information</a></li>
<li><a class="reference internal" href="#python-in-the-real-world">Python in the real world</a></li>
</ul>
</li>
</ul>
</div>
<div>
<h4>Previous topic</h4>
<p class="topless"><a href="index.html"
title="previous chapter">Python Frequently Asked Questions</a></p>
</div>
<div>
<h4>Next topic</h4>
<p class="topless"><a href="programming.html"
title="next chapter">Programming FAQ</a></p>
</div>
<div role="note" aria-label="source link">
<h3>This Page</h3>
<ul class="this-page-menu">
<li><a href="../bugs.html">Report a Bug</a></li>
<li>
<a href="https://github.com/python/cpython/blob/main/Doc/faq/general.rst"
rel="nofollow">Show Source
</a>
</li>
</ul>
</div>
</nav>
</div>
</div>
<div class="related" role="navigation" aria-label="Related">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="../genindex.html" title="General Index"
accesskey="I">index</a></li>
<li class="right" >
<a href="../py-modindex.html" title="Python Module Index"
>modules</a> |</li>
<li class="right" >
<a href="programming.html" title="Programming FAQ"
accesskey="N">next</a> |</li>
<li class="right" >
<a href="index.html" title="Python Frequently Asked Questions"
accesskey="P">previous</a> |</li>
<li><img src="../_static/py.svg" alt="Python logo" style="vertical-align: middle; margin-top: -1px"/></li>
<li><a href="https://www.python.org/">Python</a> &#187;</li>
<li class="switchers">
<div class="language_switcher_placeholder"></div>
<div class="version_switcher_placeholder"></div>
</li>
<li>
</li>
<li id="cpython-language-and-version">
<a href="../index.html">3.13.3 Documentation</a> &#187;
</li>
<li class="nav-item nav-item-1"><a href="index.html" accesskey="U">Python Frequently Asked Questions</a> &#187;</li>
<li class="nav-item nav-item-this"><a href="">General Python FAQ</a></li>
<li class="right">
<div class="inline-search" role="search">
<form class="inline-search" action="../search.html" method="get">
<input placeholder="Quick search" aria-label="Quick search" type="search" name="q" id="search-box" />
<input type="submit" value="Go" />
</form>
</div>
|
</li>
<li class="right">
<label class="theme-selector-label">
Theme
<select class="theme-selector" oninput="activateTheme(this.value)">
<option value="auto" selected>Auto</option>
<option value="light">Light</option>
<option value="dark">Dark</option>
</select>
</label> |</li>
</ul>
</div>
<div class="document">
<div class="documentwrapper">
<div class="bodywrapper">
<div class="body" role="main">
<section id="general-python-faq">
<h1><a class="toc-backref" href="#id2" role="doc-backlink">General Python FAQ</a><a class="headerlink" href="#general-python-faq" title="Link to this heading"></a></h1>
<nav class="contents" id="contents">
<p class="topic-title">Contents</p>
<ul class="simple">
<li><p><a class="reference internal" href="#general-python-faq" id="id2">General Python FAQ</a></p>
<ul>
<li><p><a class="reference internal" href="#general-information" id="id3">General Information</a></p>
<ul>
<li><p><a class="reference internal" href="#what-is-python" id="id4">What is Python?</a></p></li>
<li><p><a class="reference internal" href="#what-is-the-python-software-foundation" id="id5">What is the Python Software Foundation?</a></p></li>
<li><p><a class="reference internal" href="#are-there-copyright-restrictions-on-the-use-of-python" id="id6">Are there copyright restrictions on the use of Python?</a></p></li>
<li><p><a class="reference internal" href="#why-was-python-created-in-the-first-place" id="id7">Why was Python created in the first place?</a></p></li>
<li><p><a class="reference internal" href="#what-is-python-good-for" id="id8">What is Python good for?</a></p></li>
<li><p><a class="reference internal" href="#how-does-the-python-version-numbering-scheme-work" id="id9">How does the Python version numbering scheme work?</a></p></li>
<li><p><a class="reference internal" href="#how-do-i-obtain-a-copy-of-the-python-source" id="id10">How do I obtain a copy of the Python source?</a></p></li>
<li><p><a class="reference internal" href="#how-do-i-get-documentation-on-python" id="id11">How do I get documentation on Python?</a></p></li>
<li><p><a class="reference internal" href="#i-ve-never-programmed-before-is-there-a-python-tutorial" id="id12">Ive never programmed before. Is there a Python tutorial?</a></p></li>
<li><p><a class="reference internal" href="#is-there-a-newsgroup-or-mailing-list-devoted-to-python" id="id13">Is there a newsgroup or mailing list devoted to Python?</a></p></li>
<li><p><a class="reference internal" href="#how-do-i-get-a-beta-test-version-of-python" id="id14">How do I get a beta test version of Python?</a></p></li>
<li><p><a class="reference internal" href="#how-do-i-submit-bug-reports-and-patches-for-python" id="id15">How do I submit bug reports and patches for Python?</a></p></li>
<li><p><a class="reference internal" href="#are-there-any-published-articles-about-python-that-i-can-reference" id="id16">Are there any published articles about Python that I can reference?</a></p></li>
<li><p><a class="reference internal" href="#are-there-any-books-on-python" id="id17">Are there any books on Python?</a></p></li>
<li><p><a class="reference internal" href="#where-in-the-world-is-www-python-org-located" id="id18">Where in the world is www.python.org located?</a></p></li>
<li><p><a class="reference internal" href="#why-is-it-called-python" id="id19">Why is it called Python?</a></p></li>
<li><p><a class="reference internal" href="#do-i-have-to-like-monty-python-s-flying-circus" id="id20">Do I have to like “Monty Pythons Flying Circus”?</a></p></li>
</ul>
</li>
<li><p><a class="reference internal" href="#python-in-the-real-world" id="id21">Python in the real world</a></p>
<ul>
<li><p><a class="reference internal" href="#how-stable-is-python" id="id22">How stable is Python?</a></p></li>
<li><p><a class="reference internal" href="#how-many-people-are-using-python" id="id23">How many people are using Python?</a></p></li>
<li><p><a class="reference internal" href="#have-any-significant-projects-been-done-in-python" id="id24">Have any significant projects been done in Python?</a></p></li>
<li><p><a class="reference internal" href="#what-new-developments-are-expected-for-python-in-the-future" id="id25">What new developments are expected for Python in the future?</a></p></li>
<li><p><a class="reference internal" href="#is-it-reasonable-to-propose-incompatible-changes-to-python" id="id26">Is it reasonable to propose incompatible changes to Python?</a></p></li>
<li><p><a class="reference internal" href="#is-python-a-good-language-for-beginning-programmers" id="id27">Is Python a good language for beginning programmers?</a></p></li>
</ul>
</li>
</ul>
</li>
</ul>
</nav>
<section id="general-information">
<h2><a class="toc-backref" href="#id3" role="doc-backlink">General Information</a><a class="headerlink" href="#general-information" title="Link to this heading"></a></h2>
<section id="what-is-python">
<h3><a class="toc-backref" href="#id4" role="doc-backlink">What is Python?</a><a class="headerlink" href="#what-is-python" title="Link to this heading"></a></h3>
<p>Python is an interpreted, interactive, object-oriented programming language. It
incorporates modules, exceptions, dynamic typing, very high level dynamic data
types, and classes. It supports multiple programming paradigms beyond
object-oriented programming, such as procedural and functional programming.
Python combines remarkable power with very clear syntax. It has interfaces to
many system calls and libraries, as well as to various window systems, and is
extensible in C or C++. It is also usable as an extension language for
applications that need a programmable interface. Finally, Python is portable:
it runs on many Unix variants including Linux and macOS, and on Windows.</p>
<p>To find out more, start with <a class="reference internal" href="../tutorial/index.html#tutorial-index"><span class="std std-ref">The Python Tutorial</span></a>. The <a class="reference external" href="https://wiki.python.org/moin/BeginnersGuide">Beginners Guide to
Python</a> links to other
introductory tutorials and resources for learning Python.</p>
</section>
<section id="what-is-the-python-software-foundation">
<h3><a class="toc-backref" href="#id5" role="doc-backlink">What is the Python Software Foundation?</a><a class="headerlink" href="#what-is-the-python-software-foundation" title="Link to this heading"></a></h3>
<p>The Python Software Foundation is an independent non-profit organization that
holds the copyright on Python versions 2.1 and newer. The PSFs mission is to
advance open source technology related to the Python programming language and to
publicize the use of Python. The PSFs home page is at
<a class="reference external" href="https://www.python.org/psf/">https://www.python.org/psf/</a>.</p>
<p>Donations to the PSF are tax-exempt in the US. If you use Python and find it
helpful, please contribute via <a class="reference external" href="https://www.python.org/psf/donations/">the PSF donation page</a>.</p>
</section>
<section id="are-there-copyright-restrictions-on-the-use-of-python">
<h3><a class="toc-backref" href="#id6" role="doc-backlink">Are there copyright restrictions on the use of Python?</a><a class="headerlink" href="#are-there-copyright-restrictions-on-the-use-of-python" title="Link to this heading"></a></h3>
<p>You can do anything you want with the source, as long as you leave the
copyrights in and display those copyrights in any documentation about Python
that you produce. If you honor the copyright rules, its OK to use Python for
commercial use, to sell copies of Python in source or binary form (modified or
unmodified), or to sell products that incorporate Python in some form. We would
still like to know about all commercial use of Python, of course.</p>
<p>See <a class="reference external" href="https://docs.python.org/3/license.html">the license page</a> to find further
explanations and the full text of the PSF License.</p>
<p>The Python logo is trademarked, and in certain cases permission is required to
use it. Consult <a class="reference external" href="https://www.python.org/psf/trademarks/">the Trademark Usage Policy</a> for more information.</p>
</section>
<section id="why-was-python-created-in-the-first-place">
<h3><a class="toc-backref" href="#id7" role="doc-backlink">Why was Python created in the first place?</a><a class="headerlink" href="#why-was-python-created-in-the-first-place" title="Link to this heading"></a></h3>
<p>Heres a <em>very</em> brief summary of what started it all, written by Guido van
Rossum:</p>
<blockquote>
<div><p>I had extensive experience with implementing an interpreted language in the
ABC group at CWI, and from working with this group I had learned a lot about
language design. This is the origin of many Python features, including the
use of indentation for statement grouping and the inclusion of
very-high-level data types (although the details are all different in
Python).</p>
<p>I had a number of gripes about the ABC language, but also liked many of its
features. It was impossible to extend the ABC language (or its
implementation) to remedy my complaints in fact its lack of extensibility
was one of its biggest problems. I had some experience with using Modula-2+
and talked with the designers of Modula-3 and read the Modula-3 report.
Modula-3 is the origin of the syntax and semantics used for exceptions, and
some other Python features.</p>
<p>I was working in the Amoeba distributed operating system group at CWI. We
needed a better way to do system administration than by writing either C
programs or Bourne shell scripts, since Amoeba had its own system call
interface which wasnt easily accessible from the Bourne shell. My
experience with error handling in Amoeba made me acutely aware of the
importance of exceptions as a programming language feature.</p>
<p>It occurred to me that a scripting language with a syntax like ABC but with
access to the Amoeba system calls would fill the need. I realized that it
would be foolish to write an Amoeba-specific language, so I decided that I
needed a language that was generally extensible.</p>
<p>During the 1989 Christmas holidays, I had a lot of time on my hand, so I
decided to give it a try. During the next year, while still mostly working
on it in my own time, Python was used in the Amoeba project with increasing
success, and the feedback from colleagues made me add many early
improvements.</p>
<p>In February 1991, after just over a year of development, I decided to post to
USENET. The rest is in the <code class="docutils literal notranslate"><span class="pre">Misc/HISTORY</span></code> file.</p>
</div></blockquote>
</section>
<section id="what-is-python-good-for">
<h3><a class="toc-backref" href="#id8" role="doc-backlink">What is Python good for?</a><a class="headerlink" href="#what-is-python-good-for" title="Link to this heading"></a></h3>
<p>Python is a high-level general-purpose programming language that can be applied
to many different classes of problems.</p>
<p>The language comes with a large standard library that covers areas such as
string processing (regular expressions, Unicode, calculating differences between
files), internet protocols (HTTP, FTP, SMTP, XML-RPC, POP, IMAP),
software engineering (unit testing, logging, profiling, parsing
Python code), and operating system interfaces (system calls, filesystems, TCP/IP
sockets). Look at the table of contents for <a class="reference internal" href="../library/index.html#library-index"><span class="std std-ref">The Python Standard Library</span></a> to get an idea
of whats available. A wide variety of third-party extensions are also
available. Consult <a class="reference external" href="https://pypi.org">the Python Package Index</a> to
find packages of interest to you.</p>
</section>
<section id="how-does-the-python-version-numbering-scheme-work">
<span id="faq-version-numbering-scheme"></span><h3><a class="toc-backref" href="#id9" role="doc-backlink">How does the Python version numbering scheme work?</a><a class="headerlink" href="#how-does-the-python-version-numbering-scheme-work" title="Link to this heading"></a></h3>
<p>Python versions are numbered “A.B.C” or “A.B”:</p>
<ul class="simple">
<li><p><em>A</em> is the major version number it is only incremented for really major
changes in the language.</p></li>
<li><p><em>B</em> is the minor version number it is incremented for less earth-shattering
changes.</p></li>
<li><p><em>C</em> is the micro version number it is incremented for each bugfix release.</p></li>
</ul>
<p>Not all releases are bugfix releases. In the run-up to a new feature release, a
series of development releases are made, denoted as alpha, beta, or release
candidate. Alphas are early releases in which interfaces arent yet finalized;
its not unexpected to see an interface change between two alpha releases.
Betas are more stable, preserving existing interfaces but possibly adding new
modules, and release candidates are frozen, making no changes except as needed
to fix critical bugs.</p>
<p>Alpha, beta and release candidate versions have an additional suffix:</p>
<ul class="simple">
<li><p>The suffix for an alpha version is “aN” for some small number <em>N</em>.</p></li>
<li><p>The suffix for a beta version is “bN” for some small number <em>N</em>.</p></li>
<li><p>The suffix for a release candidate version is “rcN” for some small number <em>N</em>.</p></li>
</ul>
<p>In other words, all versions labeled <em>2.0aN</em> precede the versions labeled
<em>2.0bN</em>, which precede versions labeled <em>2.0rcN</em>, and <em>those</em> precede 2.0.</p>
<p>You may also find version numbers with a “+” suffix, e.g. “2.2+”. These are
unreleased versions, built directly from the CPython development repository. In
practice, after a final minor release is made, the version is incremented to the
next minor version, which becomes the “a0” version, e.g. “2.4a0”.</p>
<p>See the <a class="reference external" href="https://devguide.python.org/developer-workflow/development-cycle/">Developers Guide</a>
for more information about the development cycle, and
<span class="target" id="index-0"></span><a class="pep reference external" href="https://peps.python.org/pep-0387/"><strong>PEP 387</strong></a> to learn more about Pythons backward compatibility policy. See also
the documentation for <a class="reference internal" href="../library/sys.html#sys.version" title="sys.version"><code class="xref py py-data docutils literal notranslate"><span class="pre">sys.version</span></code></a>, <a class="reference internal" href="../library/sys.html#sys.hexversion" title="sys.hexversion"><code class="xref py py-data docutils literal notranslate"><span class="pre">sys.hexversion</span></code></a>, and
<a class="reference internal" href="../library/sys.html#sys.version_info" title="sys.version_info"><code class="xref py py-data docutils literal notranslate"><span class="pre">sys.version_info</span></code></a>.</p>
</section>
<section id="how-do-i-obtain-a-copy-of-the-python-source">
<h3><a class="toc-backref" href="#id10" role="doc-backlink">How do I obtain a copy of the Python source?</a><a class="headerlink" href="#how-do-i-obtain-a-copy-of-the-python-source" title="Link to this heading"></a></h3>
<p>The latest Python source distribution is always available from python.org, at
<a class="reference external" href="https://www.python.org/downloads/">https://www.python.org/downloads/</a>. The latest development sources can be obtained
at <a class="reference external" href="https://github.com/python/cpython/">https://github.com/python/cpython/</a>.</p>
<p>The source distribution is a gzipped tar file containing the complete C source,
Sphinx-formatted documentation, Python library modules, example programs, and
several useful pieces of freely distributable software. The source will compile
and run out of the box on most UNIX platforms.</p>
<p>Consult the <a class="reference external" href="https://devguide.python.org/setup/">Getting Started section of the Python Developers Guide</a> for more
information on getting the source code and compiling it.</p>
</section>
<section id="how-do-i-get-documentation-on-python">
<h3><a class="toc-backref" href="#id11" role="doc-backlink">How do I get documentation on Python?</a><a class="headerlink" href="#how-do-i-get-documentation-on-python" title="Link to this heading"></a></h3>
<p>The standard documentation for the current stable version of Python is available
at <a class="reference external" href="https://docs.python.org/3/">https://docs.python.org/3/</a>. PDF, plain text, and downloadable HTML versions are
also available at <a class="reference external" href="https://docs.python.org/3/download.html">https://docs.python.org/3/download.html</a>.</p>
<p>The documentation is written in reStructuredText and processed by <a class="reference external" href="https://www.sphinx-doc.org/">the Sphinx
documentation tool</a>. The reStructuredText source for
the documentation is part of the Python source distribution.</p>
</section>
<section id="i-ve-never-programmed-before-is-there-a-python-tutorial">
<h3><a class="toc-backref" href="#id12" role="doc-backlink">Ive never programmed before. Is there a Python tutorial?</a><a class="headerlink" href="#i-ve-never-programmed-before-is-there-a-python-tutorial" title="Link to this heading"></a></h3>
<p>There are numerous tutorials and books available. The standard documentation
includes <a class="reference internal" href="../tutorial/index.html#tutorial-index"><span class="std std-ref">The Python Tutorial</span></a>.</p>
<p>Consult <a class="reference external" href="https://wiki.python.org/moin/BeginnersGuide">the Beginners Guide</a> to
find information for beginning Python programmers, including lists of tutorials.</p>
</section>
<section id="is-there-a-newsgroup-or-mailing-list-devoted-to-python">
<h3><a class="toc-backref" href="#id13" role="doc-backlink">Is there a newsgroup or mailing list devoted to Python?</a><a class="headerlink" href="#is-there-a-newsgroup-or-mailing-list-devoted-to-python" title="Link to this heading"></a></h3>
<p>There is a newsgroup, <em class="newsgroup">comp.lang.python</em>, and a mailing list,
<a class="reference external" href="https://mail.python.org/mailman/listinfo/python-list">python-list</a>. The
newsgroup and mailing list are gatewayed into each other if you can read news
its unnecessary to subscribe to the mailing list.
<em class="newsgroup">comp.lang.python</em> is high-traffic, receiving hundreds of postings
every day, and Usenet readers are often more able to cope with this volume.</p>
<p>Announcements of new software releases and events can be found in
comp.lang.python.announce, a low-traffic moderated list that receives about five
postings per day. Its available as <a class="reference external" href="https://mail.python.org/mailman3/lists/python-announce-list.python.org/">the python-announce mailing list</a>.</p>
<p>More info about other mailing lists and newsgroups
can be found at <a class="reference external" href="https://www.python.org/community/lists/">https://www.python.org/community/lists/</a>.</p>
</section>
<section id="how-do-i-get-a-beta-test-version-of-python">
<h3><a class="toc-backref" href="#id14" role="doc-backlink">How do I get a beta test version of Python?</a><a class="headerlink" href="#how-do-i-get-a-beta-test-version-of-python" title="Link to this heading"></a></h3>
<p>Alpha and beta releases are available from <a class="reference external" href="https://www.python.org/downloads/">https://www.python.org/downloads/</a>. All
releases are announced on the comp.lang.python and comp.lang.python.announce
newsgroups and on the Python home page at <a class="reference external" href="https://www.python.org/">https://www.python.org/</a>; an RSS feed of
news is available.</p>
<p>You can also access the development version of Python through Git. See
<a class="reference external" href="https://devguide.python.org/">The Python Developers Guide</a> for details.</p>
</section>
<section id="how-do-i-submit-bug-reports-and-patches-for-python">
<h3><a class="toc-backref" href="#id15" role="doc-backlink">How do I submit bug reports and patches for Python?</a><a class="headerlink" href="#how-do-i-submit-bug-reports-and-patches-for-python" title="Link to this heading"></a></h3>
<p>To report a bug or submit a patch, use the issue tracker at
<a class="reference external" href="https://github.com/python/cpython/issues">https://github.com/python/cpython/issues</a>.</p>
<p>For more information on how Python is developed, consult <a class="reference external" href="https://devguide.python.org/">the Python Developers
Guide</a>.</p>
</section>
<section id="are-there-any-published-articles-about-python-that-i-can-reference">
<h3><a class="toc-backref" href="#id16" role="doc-backlink">Are there any published articles about Python that I can reference?</a><a class="headerlink" href="#are-there-any-published-articles-about-python-that-i-can-reference" title="Link to this heading"></a></h3>
<p>Its probably best to cite your favorite book about Python.</p>
<p>The <a class="reference external" href="https://ir.cwi.nl/pub/18204">very first article</a> about Python was
written in 1991 and is now quite outdated.</p>
<blockquote>
<div><p>Guido van Rossum and Jelke de Boer, “Interactively Testing Remote Servers
Using the Python Programming Language”, CWI Quarterly, Volume 4, Issue 4
(December 1991), Amsterdam, pp 283303.</p>
</div></blockquote>
</section>
<section id="are-there-any-books-on-python">
<h3><a class="toc-backref" href="#id17" role="doc-backlink">Are there any books on Python?</a><a class="headerlink" href="#are-there-any-books-on-python" title="Link to this heading"></a></h3>
<p>Yes, there are many, and more are being published. See the python.org wiki at
<a class="reference external" href="https://wiki.python.org/moin/PythonBooks">https://wiki.python.org/moin/PythonBooks</a> for a list.</p>
<p>You can also search online bookstores for “Python” and filter out the Monty
Python references; or perhaps search for “Python” and “language”.</p>
</section>
<section id="where-in-the-world-is-www-python-org-located">
<h3><a class="toc-backref" href="#id18" role="doc-backlink">Where in the world is www.python.org located?</a><a class="headerlink" href="#where-in-the-world-is-www-python-org-located" title="Link to this heading"></a></h3>
<p>The Python projects infrastructure is located all over the world and is managed
by the Python Infrastructure Team. Details <a class="reference external" href="https://infra.psf.io">here</a>.</p>
</section>
<section id="why-is-it-called-python">
<h3><a class="toc-backref" href="#id19" role="doc-backlink">Why is it called Python?</a><a class="headerlink" href="#why-is-it-called-python" title="Link to this heading"></a></h3>
<p>When he began implementing Python, Guido van Rossum was also reading the
published scripts from <a class="reference external" href="https://en.wikipedia.org/wiki/Monty_Python">“Monty Pythons Flying Circus”</a>, a BBC comedy series from the 1970s. Van Rossum
thought he needed a name that was short, unique, and slightly mysterious, so he
decided to call the language Python.</p>
</section>
<section id="do-i-have-to-like-monty-python-s-flying-circus">
<h3><a class="toc-backref" href="#id20" role="doc-backlink">Do I have to like “Monty Pythons Flying Circus”?</a><a class="headerlink" href="#do-i-have-to-like-monty-python-s-flying-circus" title="Link to this heading"></a></h3>
<p>No, but it helps. :)</p>
</section>
</section>
<section id="python-in-the-real-world">
<h2><a class="toc-backref" href="#id21" role="doc-backlink">Python in the real world</a><a class="headerlink" href="#python-in-the-real-world" title="Link to this heading"></a></h2>
<section id="how-stable-is-python">
<h3><a class="toc-backref" href="#id22" role="doc-backlink">How stable is Python?</a><a class="headerlink" href="#how-stable-is-python" title="Link to this heading"></a></h3>
<p>Very stable. New, stable releases have been coming out roughly every 6 to 18
months since 1991, and this seems likely to continue. As of version 3.9,
Python will have a new feature release every 12 months (<span class="target" id="index-1"></span><a class="pep reference external" href="https://peps.python.org/pep-0602/"><strong>PEP 602</strong></a>).</p>
<p>The developers issue bugfix releases of older versions, so the stability of
existing releases gradually improves. Bugfix releases, indicated by a third
component of the version number (e.g. 3.5.3, 3.6.2), are managed for stability;
only fixes for known problems are included in a bugfix release, and its
guaranteed that interfaces will remain the same throughout a series of bugfix
releases.</p>
<p>The latest stable releases can always be found on the <a class="reference external" href="https://www.python.org/downloads/">Python download page</a>.
Python 3.x is the recommended version and supported by most widely used libraries.
Python 2.x <span class="target" id="index-2"></span><a class="pep reference external" href="https://peps.python.org/pep-0373/"><strong>is not maintained anymore</strong></a>.</p>
</section>
<section id="how-many-people-are-using-python">
<h3><a class="toc-backref" href="#id23" role="doc-backlink">How many people are using Python?</a><a class="headerlink" href="#how-many-people-are-using-python" title="Link to this heading"></a></h3>
<p>There are probably millions of users, though its difficult to obtain an exact
count.</p>
<p>Python is available for free download, so there are no sales figures, and its
available from many different sites and packaged with many Linux distributions,
so download statistics dont tell the whole story either.</p>
<p>The comp.lang.python newsgroup is very active, but not all Python users post to
the group or even read it.</p>
</section>
<section id="have-any-significant-projects-been-done-in-python">
<h3><a class="toc-backref" href="#id24" role="doc-backlink">Have any significant projects been done in Python?</a><a class="headerlink" href="#have-any-significant-projects-been-done-in-python" title="Link to this heading"></a></h3>
<p>See <a class="reference external" href="https://www.python.org/about/success">https://www.python.org/about/success</a> for a list of projects that use Python.
Consulting the proceedings for <a class="reference external" href="https://www.python.org/community/workshops/">past Python conferences</a> will reveal contributions from many
different companies and organizations.</p>
<p>High-profile Python projects include <a class="reference external" href="https://www.list.org">the Mailman mailing list manager</a> and <a class="reference external" href="https://www.zope.dev">the Zope application server</a>. Several Linux distributions, most notably <a class="reference external" href="https://www.redhat.com">Red Hat</a>, have written part or all of their installer and
system administration software in Python. Companies that use Python internally
include Google, Yahoo, and Lucasfilm Ltd.</p>
</section>
<section id="what-new-developments-are-expected-for-python-in-the-future">
<h3><a class="toc-backref" href="#id25" role="doc-backlink">What new developments are expected for Python in the future?</a><a class="headerlink" href="#what-new-developments-are-expected-for-python-in-the-future" title="Link to this heading"></a></h3>
<p>See <a class="reference external" href="https://peps.python.org/">https://peps.python.org/</a> for the Python Enhancement Proposals
(PEPs). PEPs are design documents describing a suggested new feature for Python,
providing a concise technical specification and a rationale. Look for a PEP
titled “Python X.Y Release Schedule”, where X.Y is a version that hasnt been
publicly released yet.</p>
<p>New development is discussed on <a class="reference external" href="https://mail.python.org/mailman3/lists/python-dev.python.org/">the python-dev mailing list</a>.</p>
</section>
<section id="is-it-reasonable-to-propose-incompatible-changes-to-python">
<h3><a class="toc-backref" href="#id26" role="doc-backlink">Is it reasonable to propose incompatible changes to Python?</a><a class="headerlink" href="#is-it-reasonable-to-propose-incompatible-changes-to-python" title="Link to this heading"></a></h3>
<p>In general, no. There are already millions of lines of Python code around the
world, so any change in the language that invalidates more than a very small
fraction of existing programs has to be frowned upon. Even if you can provide a
conversion program, theres still the problem of updating all documentation;
many books have been written about Python, and we dont want to invalidate them
all at a single stroke.</p>
<p>Providing a gradual upgrade path is necessary if a feature has to be changed.
<span class="target" id="index-3"></span><a class="pep reference external" href="https://peps.python.org/pep-0005/"><strong>PEP 5</strong></a> describes the procedure followed for introducing backward-incompatible
changes while minimizing disruption for users.</p>
</section>
<section id="is-python-a-good-language-for-beginning-programmers">
<h3><a class="toc-backref" href="#id27" role="doc-backlink">Is Python a good language for beginning programmers?</a><a class="headerlink" href="#is-python-a-good-language-for-beginning-programmers" title="Link to this heading"></a></h3>
<p>Yes.</p>
<p>It is still common to start students with a procedural and statically typed
language such as Pascal, C, or a subset of C++ or Java. Students may be better
served by learning Python as their first language. Python has a very simple and
consistent syntax and a large standard library and, most importantly, using
Python in a beginning programming course lets students concentrate on important
programming skills such as problem decomposition and data type design. With
Python, students can be quickly introduced to basic concepts such as loops and
procedures. They can probably even work with user-defined objects in their very
first course.</p>
<p>For a student who has never programmed before, using a statically typed language
seems unnatural. It presents additional complexity that the student must master
and slows the pace of the course. The students are trying to learn to think
like a computer, decompose problems, design consistent interfaces, and
encapsulate data. While learning to use a statically typed language is
important in the long term, it is not necessarily the best topic to address in
the students first programming course.</p>
<p>Many other aspects of Python make it a good first language. Like Java, Python
has a large standard library so that students can be assigned programming
projects very early in the course that <em>do</em> something. Assignments arent
restricted to the standard four-function calculator and check balancing
programs. By using the standard library, students can gain the satisfaction of
working on realistic applications as they learn the fundamentals of programming.
Using the standard library also teaches students about code reuse. Third-party
modules such as PyGame are also helpful in extending the students reach.</p>
<p>Pythons interactive interpreter enables students to test language features
while theyre programming. They can keep a window with the interpreter running
while they enter their programs source in another window. If they cant
remember the methods for a list, they can do something like this:</p>
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">L</span> <span class="o">=</span> <span class="p">[]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">dir</span><span class="p">(</span><span class="n">L</span><span class="p">)</span>
<span class="go">[&#39;__add__&#39;, &#39;__class__&#39;, &#39;__contains__&#39;, &#39;__delattr__&#39;, &#39;__delitem__&#39;,</span>
<span class="go">&#39;__dir__&#39;, &#39;__doc__&#39;, &#39;__eq__&#39;, &#39;__format__&#39;, &#39;__ge__&#39;,</span>
<span class="go">&#39;__getattribute__&#39;, &#39;__getitem__&#39;, &#39;__gt__&#39;, &#39;__hash__&#39;, &#39;__iadd__&#39;,</span>
<span class="go">&#39;__imul__&#39;, &#39;__init__&#39;, &#39;__iter__&#39;, &#39;__le__&#39;, &#39;__len__&#39;, &#39;__lt__&#39;,</span>
<span class="go">&#39;__mul__&#39;, &#39;__ne__&#39;, &#39;__new__&#39;, &#39;__reduce__&#39;, &#39;__reduce_ex__&#39;,</span>
<span class="go">&#39;__repr__&#39;, &#39;__reversed__&#39;, &#39;__rmul__&#39;, &#39;__setattr__&#39;, &#39;__setitem__&#39;,</span>
<span class="go">&#39;__sizeof__&#39;, &#39;__str__&#39;, &#39;__subclasshook__&#39;, &#39;append&#39;, &#39;clear&#39;,</span>
<span class="go">&#39;copy&#39;, &#39;count&#39;, &#39;extend&#39;, &#39;index&#39;, &#39;insert&#39;, &#39;pop&#39;, &#39;remove&#39;,</span>
<span class="go">&#39;reverse&#39;, &#39;sort&#39;]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="p">[</span><span class="n">d</span> <span class="k">for</span> <span class="n">d</span> <span class="ow">in</span> <span class="nb">dir</span><span class="p">(</span><span class="n">L</span><span class="p">)</span> <span class="k">if</span> <span class="s1">&#39;__&#39;</span> <span class="ow">not</span> <span class="ow">in</span> <span class="n">d</span><span class="p">]</span>
<span class="go">[&#39;append&#39;, &#39;clear&#39;, &#39;copy&#39;, &#39;count&#39;, &#39;extend&#39;, &#39;index&#39;, &#39;insert&#39;, &#39;pop&#39;, &#39;remove&#39;, &#39;reverse&#39;, &#39;sort&#39;]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">help</span><span class="p">(</span><span class="n">L</span><span class="o">.</span><span class="n">append</span><span class="p">)</span>
<span class="go">Help on built-in function append:</span>
<span class="go">append(...)</span>
<span class="go"> L.append(object) -&gt; None -- append object to end</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">L</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">L</span>
<span class="go">[1]</span>
</pre></div>
</div>
<p>With the interpreter, documentation is never far from the student as they are
programming.</p>
<p>There are also good IDEs for Python. IDLE is a cross-platform IDE for Python
that is written in Python using Tkinter.
Emacs users will be happy to know that there is a very good Python mode for
Emacs. All of these programming environments provide syntax highlighting,
auto-indenting, and access to the interactive interpreter while coding. Consult
<a class="reference external" href="https://wiki.python.org/moin/PythonEditors">the Python wiki</a> for a full list
of Python editing environments.</p>
<p>If you want to discuss Pythons use in education, you may be interested in
joining <a class="reference external" href="https://www.python.org/community/sigs/current/edu-sig">the edu-sig mailing list</a>.</p>
</section>
</section>
</section>
<div class="clearer"></div>
</div>
</div>
</div>
<div class="sphinxsidebar" role="navigation" aria-label="Main">
<div class="sphinxsidebarwrapper">
<div>
<h3><a href="../contents.html">Table of Contents</a></h3>
<ul>
<li><a class="reference internal" href="#">General Python FAQ</a><ul>
<li><a class="reference internal" href="#general-information">General Information</a></li>
<li><a class="reference internal" href="#python-in-the-real-world">Python in the real world</a></li>
</ul>
</li>
</ul>
</div>
<div>
<h4>Previous topic</h4>
<p class="topless"><a href="index.html"
title="previous chapter">Python Frequently Asked Questions</a></p>
</div>
<div>
<h4>Next topic</h4>
<p class="topless"><a href="programming.html"
title="next chapter">Programming FAQ</a></p>
</div>
<div role="note" aria-label="source link">
<h3>This Page</h3>
<ul class="this-page-menu">
<li><a href="../bugs.html">Report a Bug</a></li>
<li>
<a href="https://github.com/python/cpython/blob/main/Doc/faq/general.rst"
rel="nofollow">Show Source
</a>
</li>
</ul>
</div>
</div>
<div id="sidebarbutton" title="Collapse sidebar">
<span>«</span>
</div>
</div>
<div class="clearer"></div>
</div>
<div class="related" role="navigation" aria-label="Related">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="../genindex.html" title="General Index"
>index</a></li>
<li class="right" >
<a href="../py-modindex.html" title="Python Module Index"
>modules</a> |</li>
<li class="right" >
<a href="programming.html" title="Programming FAQ"
>next</a> |</li>
<li class="right" >
<a href="index.html" title="Python Frequently Asked Questions"
>previous</a> |</li>
<li><img src="../_static/py.svg" alt="Python logo" style="vertical-align: middle; margin-top: -1px"/></li>
<li><a href="https://www.python.org/">Python</a> &#187;</li>
<li class="switchers">
<div class="language_switcher_placeholder"></div>
<div class="version_switcher_placeholder"></div>
</li>
<li>
</li>
<li id="cpython-language-and-version">
<a href="../index.html">3.13.3 Documentation</a> &#187;
</li>
<li class="nav-item nav-item-1"><a href="index.html" >Python Frequently Asked Questions</a> &#187;</li>
<li class="nav-item nav-item-this"><a href="">General Python FAQ</a></li>
<li class="right">
<div class="inline-search" role="search">
<form class="inline-search" action="../search.html" method="get">
<input placeholder="Quick search" aria-label="Quick search" type="search" name="q" id="search-box" />
<input type="submit" value="Go" />
</form>
</div>
|
</li>
<li class="right">
<label class="theme-selector-label">
Theme
<select class="theme-selector" oninput="activateTheme(this.value)">
<option value="auto" selected>Auto</option>
<option value="light">Light</option>
<option value="dark">Dark</option>
</select>
</label> |</li>
</ul>
</div>
<div class="footer">
&copy;
<a href="../copyright.html">
Copyright
</a>
2001-2025, Python Software Foundation.
<br />
This page is licensed under the Python Software Foundation License Version 2.
<br />
Examples, recipes, and other code in the documentation are additionally licensed under the Zero Clause BSD License.
<br />
See <a href="/license.html">History and License</a> for more information.<br />
<br />
The Python Software Foundation is a non-profit corporation.
<a href="https://www.python.org/psf/donations/">Please donate.</a>
<br />
<br />
Last updated on Apr 08, 2025 (14:33 UTC).
<a href="/bugs.html">Found a bug</a>?
<br />
Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 8.2.3.
</div>
</body>
</html>

View File

@@ -0,0 +1,402 @@
<!DOCTYPE html>
<html lang="en" data-content_root="../">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="viewport" content="width=device-width, initial-scale=1" />
<meta property="og:title" content="Graphic User Interface FAQ" />
<meta property="og:type" content="website" />
<meta property="og:url" content="https://docs.python.org/3/faq/gui.html" />
<meta property="og:site_name" content="Python documentation" />
<meta property="og:description" content="Contents: Graphic User Interface FAQ- General GUI Questions, What GUI toolkits exist for Python?, Tkinter questions- How do I freeze Tkinter applications?, Can I have Tk events handled while waitin..." />
<meta property="og:image" content="https://docs.python.org/3/_static/og-image.png" />
<meta property="og:image:alt" content="Python documentation" />
<meta name="description" content="Contents: Graphic User Interface FAQ- General GUI Questions, What GUI toolkits exist for Python?, Tkinter questions- How do I freeze Tkinter applications?, Can I have Tk events handled while waitin..." />
<meta property="og:image:width" content="200">
<meta property="og:image:height" content="200">
<meta name="theme-color" content="#3776ab">
<title>Graphic User Interface FAQ &#8212; Python 3.13.3 documentation</title><meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" type="text/css" href="../_static/pygments.css?v=b86133f3" />
<link rel="stylesheet" type="text/css" href="../_static/pydoctheme.css?v=23252803" />
<link id="pygments_dark_css" media="(prefers-color-scheme: dark)" rel="stylesheet" type="text/css" href="../_static/pygments_dark.css?v=5349f25f" />
<script src="../_static/documentation_options.js?v=5d57ca2d"></script>
<script src="../_static/doctools.js?v=9bcbadda"></script>
<script src="../_static/sphinx_highlight.js?v=dc90522c"></script>
<script src="../_static/sidebar.js"></script>
<link rel="search" type="application/opensearchdescription+xml"
title="Search within Python 3.13.3 documentation"
href="../_static/opensearch.xml"/>
<link rel="author" title="About these documents" href="../about.html" />
<link rel="index" title="Index" href="../genindex.html" />
<link rel="search" title="Search" href="../search.html" />
<link rel="copyright" title="Copyright" href="../copyright.html" />
<link rel="next" title="“Why is Python Installed on my Computer?” FAQ" href="installed.html" />
<link rel="prev" title="Python on Windows FAQ" href="windows.html" />
<link rel="canonical" href="https://docs.python.org/3/faq/gui.html">
<style>
@media only screen {
table.full-width-table {
width: 100%;
}
}
</style>
<link rel="stylesheet" href="../_static/pydoctheme_dark.css" media="(prefers-color-scheme: dark)" id="pydoctheme_dark_css">
<link rel="shortcut icon" type="image/png" href="../_static/py.svg" />
<script type="text/javascript" src="../_static/copybutton.js"></script>
<script type="text/javascript" src="../_static/menu.js"></script>
<script type="text/javascript" src="../_static/search-focus.js"></script>
<script type="text/javascript" src="../_static/themetoggle.js"></script>
<script type="text/javascript" src="../_static/rtd_switcher.js"></script>
<meta name="readthedocs-addons-api-version" content="1">
</head>
<body>
<div class="mobile-nav">
<input type="checkbox" id="menuToggler" class="toggler__input" aria-controls="navigation"
aria-pressed="false" aria-expanded="false" role="button" aria-label="Menu" />
<nav class="nav-content" role="navigation">
<label for="menuToggler" class="toggler__label">
<span></span>
</label>
<span class="nav-items-wrapper">
<a href="https://www.python.org/" class="nav-logo">
<img src="../_static/py.svg" alt="Python logo"/>
</a>
<span class="version_switcher_placeholder"></span>
<form role="search" class="search" action="../search.html" method="get">
<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" class="search-icon">
<path fill-rule="nonzero" 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>
</svg>
<input placeholder="Quick search" aria-label="Quick search" type="search" name="q" />
<input type="submit" value="Go"/>
</form>
</span>
</nav>
<div class="menu-wrapper">
<nav class="menu" role="navigation" aria-label="main navigation">
<div class="language_switcher_placeholder"></div>
<label class="theme-selector-label">
Theme
<select class="theme-selector" oninput="activateTheme(this.value)">
<option value="auto" selected>Auto</option>
<option value="light">Light</option>
<option value="dark">Dark</option>
</select>
</label>
<div>
<h3><a href="../contents.html">Table of Contents</a></h3>
<ul>
<li><a class="reference internal" href="#">Graphic User Interface FAQ</a><ul>
<li><a class="reference internal" href="#general-gui-questions">General GUI Questions</a></li>
<li><a class="reference internal" href="#what-gui-toolkits-exist-for-python">What GUI toolkits exist for Python?</a></li>
<li><a class="reference internal" href="#tkinter-questions">Tkinter questions</a></li>
</ul>
</li>
</ul>
</div>
<div>
<h4>Previous topic</h4>
<p class="topless"><a href="windows.html"
title="previous chapter">Python on Windows FAQ</a></p>
</div>
<div>
<h4>Next topic</h4>
<p class="topless"><a href="installed.html"
title="next chapter">“Why is Python Installed on my Computer?” FAQ</a></p>
</div>
<div role="note" aria-label="source link">
<h3>This Page</h3>
<ul class="this-page-menu">
<li><a href="../bugs.html">Report a Bug</a></li>
<li>
<a href="https://github.com/python/cpython/blob/main/Doc/faq/gui.rst"
rel="nofollow">Show Source
</a>
</li>
</ul>
</div>
</nav>
</div>
</div>
<div class="related" role="navigation" aria-label="Related">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="../genindex.html" title="General Index"
accesskey="I">index</a></li>
<li class="right" >
<a href="../py-modindex.html" title="Python Module Index"
>modules</a> |</li>
<li class="right" >
<a href="installed.html" title="“Why is Python Installed on my Computer?” FAQ"
accesskey="N">next</a> |</li>
<li class="right" >
<a href="windows.html" title="Python on Windows FAQ"
accesskey="P">previous</a> |</li>
<li><img src="../_static/py.svg" alt="Python logo" style="vertical-align: middle; margin-top: -1px"/></li>
<li><a href="https://www.python.org/">Python</a> &#187;</li>
<li class="switchers">
<div class="language_switcher_placeholder"></div>
<div class="version_switcher_placeholder"></div>
</li>
<li>
</li>
<li id="cpython-language-and-version">
<a href="../index.html">3.13.3 Documentation</a> &#187;
</li>
<li class="nav-item nav-item-1"><a href="index.html" accesskey="U">Python Frequently Asked Questions</a> &#187;</li>
<li class="nav-item nav-item-this"><a href="">Graphic User Interface FAQ</a></li>
<li class="right">
<div class="inline-search" role="search">
<form class="inline-search" action="../search.html" method="get">
<input placeholder="Quick search" aria-label="Quick search" type="search" name="q" id="search-box" />
<input type="submit" value="Go" />
</form>
</div>
|
</li>
<li class="right">
<label class="theme-selector-label">
Theme
<select class="theme-selector" oninput="activateTheme(this.value)">
<option value="auto" selected>Auto</option>
<option value="light">Light</option>
<option value="dark">Dark</option>
</select>
</label> |</li>
</ul>
</div>
<div class="document">
<div class="documentwrapper">
<div class="bodywrapper">
<div class="body" role="main">
<section id="graphic-user-interface-faq">
<h1><a class="toc-backref" href="#id1" role="doc-backlink">Graphic User Interface FAQ</a><a class="headerlink" href="#graphic-user-interface-faq" title="Link to this heading"></a></h1>
<nav class="contents" id="contents">
<p class="topic-title">Contents</p>
<ul class="simple">
<li><p><a class="reference internal" href="#graphic-user-interface-faq" id="id1">Graphic User Interface FAQ</a></p>
<ul>
<li><p><a class="reference internal" href="#general-gui-questions" id="id2">General GUI Questions</a></p></li>
<li><p><a class="reference internal" href="#what-gui-toolkits-exist-for-python" id="id3">What GUI toolkits exist for Python?</a></p></li>
<li><p><a class="reference internal" href="#tkinter-questions" id="id4">Tkinter questions</a></p>
<ul>
<li><p><a class="reference internal" href="#how-do-i-freeze-tkinter-applications" id="id5">How do I freeze Tkinter applications?</a></p></li>
<li><p><a class="reference internal" href="#can-i-have-tk-events-handled-while-waiting-for-i-o" id="id6">Can I have Tk events handled while waiting for I/O?</a></p></li>
<li><p><a class="reference internal" href="#i-can-t-get-key-bindings-to-work-in-tkinter-why" id="id7">I cant get key bindings to work in Tkinter: why?</a></p></li>
</ul>
</li>
</ul>
</li>
</ul>
</nav>
<section id="general-gui-questions">
<h2><a class="toc-backref" href="#id2" role="doc-backlink">General GUI Questions</a><a class="headerlink" href="#general-gui-questions" title="Link to this heading"></a></h2>
</section>
<section id="what-gui-toolkits-exist-for-python">
<h2><a class="toc-backref" href="#id3" role="doc-backlink">What GUI toolkits exist for Python?</a><a class="headerlink" href="#what-gui-toolkits-exist-for-python" title="Link to this heading"></a></h2>
<p>Standard builds of Python include an object-oriented interface to the Tcl/Tk
widget set, called <a class="reference internal" href="../library/tk.html#tkinter"><span class="std std-ref">tkinter</span></a>. This is probably the easiest to
install (since it comes included with most
<a class="reference external" href="https://www.python.org/downloads/">binary distributions</a> of Python) and use.
For more info about Tk, including pointers to the source, see the
<a class="reference external" href="https://www.tcl.tk">Tcl/Tk home page</a>. Tcl/Tk is fully portable to the
macOS, Windows, and Unix platforms.</p>
<p>Depending on what platform(s) you are aiming at, there are also several
alternatives. A <a class="reference external" href="https://wiki.python.org/moin/GuiProgramming#Cross-Platform_Frameworks">list of cross-platform</a> and
<a class="reference external" href="https://wiki.python.org/moin/GuiProgramming#Platform-specific_Frameworks">platform-specific</a> GUI
frameworks can be found on the python wiki.</p>
</section>
<section id="tkinter-questions">
<h2><a class="toc-backref" href="#id4" role="doc-backlink">Tkinter questions</a><a class="headerlink" href="#tkinter-questions" title="Link to this heading"></a></h2>
<section id="how-do-i-freeze-tkinter-applications">
<h3><a class="toc-backref" href="#id5" role="doc-backlink">How do I freeze Tkinter applications?</a><a class="headerlink" href="#how-do-i-freeze-tkinter-applications" title="Link to this heading"></a></h3>
<p>Freeze is a tool to create stand-alone applications. When freezing Tkinter
applications, the applications will not be truly stand-alone, as the application
will still need the Tcl and Tk libraries.</p>
<p>One solution is to ship the application with the Tcl and Tk libraries, and point
to them at run-time using the <code class="xref std std-envvar docutils literal notranslate"><span class="pre">TCL_LIBRARY</span></code> and <code class="xref std std-envvar docutils literal notranslate"><span class="pre">TK_LIBRARY</span></code>
environment variables.</p>
<p>Various third-party freeze libraries such as py2exe and cx_Freeze have
handling for Tkinter applications built-in.</p>
</section>
<section id="can-i-have-tk-events-handled-while-waiting-for-i-o">
<h3><a class="toc-backref" href="#id6" role="doc-backlink">Can I have Tk events handled while waiting for I/O?</a><a class="headerlink" href="#can-i-have-tk-events-handled-while-waiting-for-i-o" title="Link to this heading"></a></h3>
<p>On platforms other than Windows, yes, and you dont even
need threads! But youll have to restructure your I/O
code a bit. Tk has the equivalent of Xts <code class="xref c c-func docutils literal notranslate"><span class="pre">XtAddInput()</span></code> call, which allows you
to register a callback function which will be called from the Tk mainloop when
I/O is possible on a file descriptor. See <a class="reference internal" href="../library/tkinter.html#tkinter-file-handlers"><span class="std std-ref">File Handlers</span></a>.</p>
</section>
<section id="i-can-t-get-key-bindings-to-work-in-tkinter-why">
<h3><a class="toc-backref" href="#id7" role="doc-backlink">I cant get key bindings to work in Tkinter: why?</a><a class="headerlink" href="#i-can-t-get-key-bindings-to-work-in-tkinter-why" title="Link to this heading"></a></h3>
<p>An often-heard complaint is that event handlers <a class="reference internal" href="../library/tkinter.html#bindings-and-events"><span class="std std-ref">bound</span></a>
to events with the <code class="xref py py-meth docutils literal notranslate"><span class="pre">bind()</span></code> method
dont get handled even when the appropriate key is pressed.</p>
<p>The most common cause is that the widget to which the binding applies doesnt
have “keyboard focus”. Check out the Tk documentation for the focus command.
Usually a widget is given the keyboard focus by clicking in it (but not for
labels; see the takefocus option).</p>
</section>
</section>
</section>
<div class="clearer"></div>
</div>
</div>
</div>
<div class="sphinxsidebar" role="navigation" aria-label="Main">
<div class="sphinxsidebarwrapper">
<div>
<h3><a href="../contents.html">Table of Contents</a></h3>
<ul>
<li><a class="reference internal" href="#">Graphic User Interface FAQ</a><ul>
<li><a class="reference internal" href="#general-gui-questions">General GUI Questions</a></li>
<li><a class="reference internal" href="#what-gui-toolkits-exist-for-python">What GUI toolkits exist for Python?</a></li>
<li><a class="reference internal" href="#tkinter-questions">Tkinter questions</a></li>
</ul>
</li>
</ul>
</div>
<div>
<h4>Previous topic</h4>
<p class="topless"><a href="windows.html"
title="previous chapter">Python on Windows FAQ</a></p>
</div>
<div>
<h4>Next topic</h4>
<p class="topless"><a href="installed.html"
title="next chapter">“Why is Python Installed on my Computer?” FAQ</a></p>
</div>
<div role="note" aria-label="source link">
<h3>This Page</h3>
<ul class="this-page-menu">
<li><a href="../bugs.html">Report a Bug</a></li>
<li>
<a href="https://github.com/python/cpython/blob/main/Doc/faq/gui.rst"
rel="nofollow">Show Source
</a>
</li>
</ul>
</div>
</div>
<div id="sidebarbutton" title="Collapse sidebar">
<span>«</span>
</div>
</div>
<div class="clearer"></div>
</div>
<div class="related" role="navigation" aria-label="Related">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="../genindex.html" title="General Index"
>index</a></li>
<li class="right" >
<a href="../py-modindex.html" title="Python Module Index"
>modules</a> |</li>
<li class="right" >
<a href="installed.html" title="“Why is Python Installed on my Computer?” FAQ"
>next</a> |</li>
<li class="right" >
<a href="windows.html" title="Python on Windows FAQ"
>previous</a> |</li>
<li><img src="../_static/py.svg" alt="Python logo" style="vertical-align: middle; margin-top: -1px"/></li>
<li><a href="https://www.python.org/">Python</a> &#187;</li>
<li class="switchers">
<div class="language_switcher_placeholder"></div>
<div class="version_switcher_placeholder"></div>
</li>
<li>
</li>
<li id="cpython-language-and-version">
<a href="../index.html">3.13.3 Documentation</a> &#187;
</li>
<li class="nav-item nav-item-1"><a href="index.html" >Python Frequently Asked Questions</a> &#187;</li>
<li class="nav-item nav-item-this"><a href="">Graphic User Interface FAQ</a></li>
<li class="right">
<div class="inline-search" role="search">
<form class="inline-search" action="../search.html" method="get">
<input placeholder="Quick search" aria-label="Quick search" type="search" name="q" id="search-box" />
<input type="submit" value="Go" />
</form>
</div>
|
</li>
<li class="right">
<label class="theme-selector-label">
Theme
<select class="theme-selector" oninput="activateTheme(this.value)">
<option value="auto" selected>Auto</option>
<option value="light">Light</option>
<option value="dark">Dark</option>
</select>
</label> |</li>
</ul>
</div>
<div class="footer">
&copy;
<a href="../copyright.html">
Copyright
</a>
2001-2025, Python Software Foundation.
<br />
This page is licensed under the Python Software Foundation License Version 2.
<br />
Examples, recipes, and other code in the documentation are additionally licensed under the Zero Clause BSD License.
<br />
See <a href="/license.html">History and License</a> for more information.<br />
<br />
The Python Software Foundation is a non-profit corporation.
<a href="https://www.python.org/psf/donations/">Please donate.</a>
<br />
<br />
Last updated on Apr 08, 2025 (14:33 UTC).
<a href="/bugs.html">Found a bug</a>?
<br />
Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 8.2.3.
</div>
</body>
</html>

View File

@@ -0,0 +1,321 @@
<!DOCTYPE html>
<html lang="en" data-content_root="../">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="viewport" content="width=device-width, initial-scale=1" />
<meta property="og:title" content="Python Frequently Asked Questions" />
<meta property="og:type" content="website" />
<meta property="og:url" content="https://docs.python.org/3/faq/index.html" />
<meta property="og:site_name" content="Python documentation" />
<meta property="og:description" content="General Python FAQ, Programming FAQ, Design and History FAQ, Library and Extension FAQ, Extending/Embedding FAQ, Python on Windows FAQ, Graphic User Interface FAQ, “Why is Python Installed on my Co..." />
<meta property="og:image" content="https://docs.python.org/3/_static/og-image.png" />
<meta property="og:image:alt" content="Python documentation" />
<meta name="description" content="General Python FAQ, Programming FAQ, Design and History FAQ, Library and Extension FAQ, Extending/Embedding FAQ, Python on Windows FAQ, Graphic User Interface FAQ, “Why is Python Installed on my Co..." />
<meta property="og:image:width" content="200">
<meta property="og:image:height" content="200">
<meta name="theme-color" content="#3776ab">
<title>Python Frequently Asked Questions &#8212; Python 3.13.3 documentation</title><meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" type="text/css" href="../_static/pygments.css?v=b86133f3" />
<link rel="stylesheet" type="text/css" href="../_static/pydoctheme.css?v=23252803" />
<link id="pygments_dark_css" media="(prefers-color-scheme: dark)" rel="stylesheet" type="text/css" href="../_static/pygments_dark.css?v=5349f25f" />
<script src="../_static/documentation_options.js?v=5d57ca2d"></script>
<script src="../_static/doctools.js?v=9bcbadda"></script>
<script src="../_static/sphinx_highlight.js?v=dc90522c"></script>
<script src="../_static/sidebar.js"></script>
<link rel="search" type="application/opensearchdescription+xml"
title="Search within Python 3.13.3 documentation"
href="../_static/opensearch.xml"/>
<link rel="author" title="About these documents" href="../about.html" />
<link rel="index" title="Index" href="../genindex.html" />
<link rel="search" title="Search" href="../search.html" />
<link rel="copyright" title="Copyright" href="../copyright.html" />
<link rel="next" title="General Python FAQ" href="general.html" />
<link rel="prev" title="C API Extension Support for Free Threading" href="../howto/free-threading-extensions.html" />
<link rel="canonical" href="https://docs.python.org/3/faq/index.html">
<style>
@media only screen {
table.full-width-table {
width: 100%;
}
}
</style>
<link rel="stylesheet" href="../_static/pydoctheme_dark.css" media="(prefers-color-scheme: dark)" id="pydoctheme_dark_css">
<link rel="shortcut icon" type="image/png" href="../_static/py.svg" />
<script type="text/javascript" src="../_static/copybutton.js"></script>
<script type="text/javascript" src="../_static/menu.js"></script>
<script type="text/javascript" src="../_static/search-focus.js"></script>
<script type="text/javascript" src="../_static/themetoggle.js"></script>
<script type="text/javascript" src="../_static/rtd_switcher.js"></script>
<meta name="readthedocs-addons-api-version" content="1">
</head>
<body>
<div class="mobile-nav">
<input type="checkbox" id="menuToggler" class="toggler__input" aria-controls="navigation"
aria-pressed="false" aria-expanded="false" role="button" aria-label="Menu" />
<nav class="nav-content" role="navigation">
<label for="menuToggler" class="toggler__label">
<span></span>
</label>
<span class="nav-items-wrapper">
<a href="https://www.python.org/" class="nav-logo">
<img src="../_static/py.svg" alt="Python logo"/>
</a>
<span class="version_switcher_placeholder"></span>
<form role="search" class="search" action="../search.html" method="get">
<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" class="search-icon">
<path fill-rule="nonzero" 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>
</svg>
<input placeholder="Quick search" aria-label="Quick search" type="search" name="q" />
<input type="submit" value="Go"/>
</form>
</span>
</nav>
<div class="menu-wrapper">
<nav class="menu" role="navigation" aria-label="main navigation">
<div class="language_switcher_placeholder"></div>
<label class="theme-selector-label">
Theme
<select class="theme-selector" oninput="activateTheme(this.value)">
<option value="auto" selected>Auto</option>
<option value="light">Light</option>
<option value="dark">Dark</option>
</select>
</label>
<div>
<h4>Previous topic</h4>
<p class="topless"><a href="../howto/free-threading-extensions.html"
title="previous chapter">C API Extension Support for Free Threading</a></p>
</div>
<div>
<h4>Next topic</h4>
<p class="topless"><a href="general.html"
title="next chapter">General Python FAQ</a></p>
</div>
<div role="note" aria-label="source link">
<h3>This Page</h3>
<ul class="this-page-menu">
<li><a href="../bugs.html">Report a Bug</a></li>
<li>
<a href="https://github.com/python/cpython/blob/main/Doc/faq/index.rst"
rel="nofollow">Show Source
</a>
</li>
</ul>
</div>
</nav>
</div>
</div>
<div class="related" role="navigation" aria-label="Related">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="../genindex.html" title="General Index"
accesskey="I">index</a></li>
<li class="right" >
<a href="../py-modindex.html" title="Python Module Index"
>modules</a> |</li>
<li class="right" >
<a href="general.html" title="General Python FAQ"
accesskey="N">next</a> |</li>
<li class="right" >
<a href="../howto/free-threading-extensions.html" title="C API Extension Support for Free Threading"
accesskey="P">previous</a> |</li>
<li><img src="../_static/py.svg" alt="Python logo" style="vertical-align: middle; margin-top: -1px"/></li>
<li><a href="https://www.python.org/">Python</a> &#187;</li>
<li class="switchers">
<div class="language_switcher_placeholder"></div>
<div class="version_switcher_placeholder"></div>
</li>
<li>
</li>
<li id="cpython-language-and-version">
<a href="../index.html">3.13.3 Documentation</a> &#187;
</li>
<li class="nav-item nav-item-this"><a href="">Python Frequently Asked Questions</a></li>
<li class="right">
<div class="inline-search" role="search">
<form class="inline-search" action="../search.html" method="get">
<input placeholder="Quick search" aria-label="Quick search" type="search" name="q" id="search-box" />
<input type="submit" value="Go" />
</form>
</div>
|
</li>
<li class="right">
<label class="theme-selector-label">
Theme
<select class="theme-selector" oninput="activateTheme(this.value)">
<option value="auto" selected>Auto</option>
<option value="light">Light</option>
<option value="dark">Dark</option>
</select>
</label> |</li>
</ul>
</div>
<div class="document">
<div class="documentwrapper">
<div class="bodywrapper">
<div class="body" role="main">
<section id="python-frequently-asked-questions">
<span id="faq-index"></span><h1>Python Frequently Asked Questions<a class="headerlink" href="#python-frequently-asked-questions" title="Link to this heading"></a></h1>
<div class="toctree-wrapper compound">
<ul>
<li class="toctree-l1"><a class="reference internal" href="general.html">General Python FAQ</a></li>
<li class="toctree-l1"><a class="reference internal" href="programming.html">Programming FAQ</a></li>
<li class="toctree-l1"><a class="reference internal" href="design.html">Design and History FAQ</a></li>
<li class="toctree-l1"><a class="reference internal" href="library.html">Library and Extension FAQ</a></li>
<li class="toctree-l1"><a class="reference internal" href="extending.html">Extending/Embedding FAQ</a></li>
<li class="toctree-l1"><a class="reference internal" href="windows.html">Python on Windows FAQ</a></li>
<li class="toctree-l1"><a class="reference internal" href="gui.html">Graphic User Interface FAQ</a></li>
<li class="toctree-l1"><a class="reference internal" href="installed.html">“Why is Python Installed on my Computer?” FAQ</a></li>
</ul>
</div>
</section>
<div class="clearer"></div>
</div>
</div>
</div>
<div class="sphinxsidebar" role="navigation" aria-label="Main">
<div class="sphinxsidebarwrapper">
<div>
<h4>Previous topic</h4>
<p class="topless"><a href="../howto/free-threading-extensions.html"
title="previous chapter">C API Extension Support for Free Threading</a></p>
</div>
<div>
<h4>Next topic</h4>
<p class="topless"><a href="general.html"
title="next chapter">General Python FAQ</a></p>
</div>
<div role="note" aria-label="source link">
<h3>This Page</h3>
<ul class="this-page-menu">
<li><a href="../bugs.html">Report a Bug</a></li>
<li>
<a href="https://github.com/python/cpython/blob/main/Doc/faq/index.rst"
rel="nofollow">Show Source
</a>
</li>
</ul>
</div>
</div>
<div id="sidebarbutton" title="Collapse sidebar">
<span>«</span>
</div>
</div>
<div class="clearer"></div>
</div>
<div class="related" role="navigation" aria-label="Related">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="../genindex.html" title="General Index"
>index</a></li>
<li class="right" >
<a href="../py-modindex.html" title="Python Module Index"
>modules</a> |</li>
<li class="right" >
<a href="general.html" title="General Python FAQ"
>next</a> |</li>
<li class="right" >
<a href="../howto/free-threading-extensions.html" title="C API Extension Support for Free Threading"
>previous</a> |</li>
<li><img src="../_static/py.svg" alt="Python logo" style="vertical-align: middle; margin-top: -1px"/></li>
<li><a href="https://www.python.org/">Python</a> &#187;</li>
<li class="switchers">
<div class="language_switcher_placeholder"></div>
<div class="version_switcher_placeholder"></div>
</li>
<li>
</li>
<li id="cpython-language-and-version">
<a href="../index.html">3.13.3 Documentation</a> &#187;
</li>
<li class="nav-item nav-item-this"><a href="">Python Frequently Asked Questions</a></li>
<li class="right">
<div class="inline-search" role="search">
<form class="inline-search" action="../search.html" method="get">
<input placeholder="Quick search" aria-label="Quick search" type="search" name="q" id="search-box" />
<input type="submit" value="Go" />
</form>
</div>
|
</li>
<li class="right">
<label class="theme-selector-label">
Theme
<select class="theme-selector" oninput="activateTheme(this.value)">
<option value="auto" selected>Auto</option>
<option value="light">Light</option>
<option value="dark">Dark</option>
</select>
</label> |</li>
</ul>
</div>
<div class="footer">
&copy;
<a href="../copyright.html">
Copyright
</a>
2001-2025, Python Software Foundation.
<br />
This page is licensed under the Python Software Foundation License Version 2.
<br />
Examples, recipes, and other code in the documentation are additionally licensed under the Zero Clause BSD License.
<br />
See <a href="/license.html">History and License</a> for more information.<br />
<br />
The Python Software Foundation is a non-profit corporation.
<a href="https://www.python.org/psf/donations/">Please donate.</a>
<br />
<br />
Last updated on Apr 08, 2025 (14:33 UTC).
<a href="/bugs.html">Found a bug</a>?
<br />
Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 8.2.3.
</div>
</body>
</html>

View File

@@ -0,0 +1,376 @@
<!DOCTYPE html>
<html lang="en" data-content_root="../">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="viewport" content="width=device-width, initial-scale=1" />
<meta property="og:title" content="“Why is Python Installed on my Computer?” FAQ" />
<meta property="og:type" content="website" />
<meta property="og:url" content="https://docs.python.org/3/faq/installed.html" />
<meta property="og:site_name" content="Python documentation" />
<meta property="og:description" content="What is Python?: Python is a programming language. Its used for many different applications. Its used in some high schools and colleges as an introductory programming language because Python is e..." />
<meta property="og:image" content="https://docs.python.org/3/_static/og-image.png" />
<meta property="og:image:alt" content="Python documentation" />
<meta name="description" content="What is Python?: Python is a programming language. Its used for many different applications. Its used in some high schools and colleges as an introductory programming language because Python is e..." />
<meta property="og:image:width" content="200">
<meta property="og:image:height" content="200">
<meta name="theme-color" content="#3776ab">
<title>“Why is Python Installed on my Computer?” FAQ &#8212; Python 3.13.3 documentation</title><meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" type="text/css" href="../_static/pygments.css?v=b86133f3" />
<link rel="stylesheet" type="text/css" href="../_static/pydoctheme.css?v=23252803" />
<link id="pygments_dark_css" media="(prefers-color-scheme: dark)" rel="stylesheet" type="text/css" href="../_static/pygments_dark.css?v=5349f25f" />
<script src="../_static/documentation_options.js?v=5d57ca2d"></script>
<script src="../_static/doctools.js?v=9bcbadda"></script>
<script src="../_static/sphinx_highlight.js?v=dc90522c"></script>
<script src="../_static/sidebar.js"></script>
<link rel="search" type="application/opensearchdescription+xml"
title="Search within Python 3.13.3 documentation"
href="../_static/opensearch.xml"/>
<link rel="author" title="About these documents" href="../about.html" />
<link rel="index" title="Index" href="../genindex.html" />
<link rel="search" title="Search" href="../search.html" />
<link rel="copyright" title="Copyright" href="../copyright.html" />
<link rel="next" title="Deprecations" href="../deprecations/index.html" />
<link rel="prev" title="Graphic User Interface FAQ" href="gui.html" />
<link rel="canonical" href="https://docs.python.org/3/faq/installed.html">
<style>
@media only screen {
table.full-width-table {
width: 100%;
}
}
</style>
<link rel="stylesheet" href="../_static/pydoctheme_dark.css" media="(prefers-color-scheme: dark)" id="pydoctheme_dark_css">
<link rel="shortcut icon" type="image/png" href="../_static/py.svg" />
<script type="text/javascript" src="../_static/copybutton.js"></script>
<script type="text/javascript" src="../_static/menu.js"></script>
<script type="text/javascript" src="../_static/search-focus.js"></script>
<script type="text/javascript" src="../_static/themetoggle.js"></script>
<script type="text/javascript" src="../_static/rtd_switcher.js"></script>
<meta name="readthedocs-addons-api-version" content="1">
</head>
<body>
<div class="mobile-nav">
<input type="checkbox" id="menuToggler" class="toggler__input" aria-controls="navigation"
aria-pressed="false" aria-expanded="false" role="button" aria-label="Menu" />
<nav class="nav-content" role="navigation">
<label for="menuToggler" class="toggler__label">
<span></span>
</label>
<span class="nav-items-wrapper">
<a href="https://www.python.org/" class="nav-logo">
<img src="../_static/py.svg" alt="Python logo"/>
</a>
<span class="version_switcher_placeholder"></span>
<form role="search" class="search" action="../search.html" method="get">
<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" class="search-icon">
<path fill-rule="nonzero" 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>
</svg>
<input placeholder="Quick search" aria-label="Quick search" type="search" name="q" />
<input type="submit" value="Go"/>
</form>
</span>
</nav>
<div class="menu-wrapper">
<nav class="menu" role="navigation" aria-label="main navigation">
<div class="language_switcher_placeholder"></div>
<label class="theme-selector-label">
Theme
<select class="theme-selector" oninput="activateTheme(this.value)">
<option value="auto" selected>Auto</option>
<option value="light">Light</option>
<option value="dark">Dark</option>
</select>
</label>
<div>
<h3><a href="../contents.html">Table of Contents</a></h3>
<ul>
<li><a class="reference internal" href="#">“Why is Python Installed on my Computer?” FAQ</a><ul>
<li><a class="reference internal" href="#what-is-python">What is Python?</a></li>
<li><a class="reference internal" href="#why-is-python-installed-on-my-machine">Why is Python installed on my machine?</a></li>
<li><a class="reference internal" href="#can-i-delete-python">Can I delete Python?</a></li>
</ul>
</li>
</ul>
</div>
<div>
<h4>Previous topic</h4>
<p class="topless"><a href="gui.html"
title="previous chapter">Graphic User Interface FAQ</a></p>
</div>
<div>
<h4>Next topic</h4>
<p class="topless"><a href="../deprecations/index.html"
title="next chapter">Deprecations</a></p>
</div>
<div role="note" aria-label="source link">
<h3>This Page</h3>
<ul class="this-page-menu">
<li><a href="../bugs.html">Report a Bug</a></li>
<li>
<a href="https://github.com/python/cpython/blob/main/Doc/faq/installed.rst"
rel="nofollow">Show Source
</a>
</li>
</ul>
</div>
</nav>
</div>
</div>
<div class="related" role="navigation" aria-label="Related">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="../genindex.html" title="General Index"
accesskey="I">index</a></li>
<li class="right" >
<a href="../py-modindex.html" title="Python Module Index"
>modules</a> |</li>
<li class="right" >
<a href="../deprecations/index.html" title="Deprecations"
accesskey="N">next</a> |</li>
<li class="right" >
<a href="gui.html" title="Graphic User Interface FAQ"
accesskey="P">previous</a> |</li>
<li><img src="../_static/py.svg" alt="Python logo" style="vertical-align: middle; margin-top: -1px"/></li>
<li><a href="https://www.python.org/">Python</a> &#187;</li>
<li class="switchers">
<div class="language_switcher_placeholder"></div>
<div class="version_switcher_placeholder"></div>
</li>
<li>
</li>
<li id="cpython-language-and-version">
<a href="../index.html">3.13.3 Documentation</a> &#187;
</li>
<li class="nav-item nav-item-1"><a href="index.html" accesskey="U">Python Frequently Asked Questions</a> &#187;</li>
<li class="nav-item nav-item-this"><a href="">“Why is Python Installed on my Computer?” FAQ</a></li>
<li class="right">
<div class="inline-search" role="search">
<form class="inline-search" action="../search.html" method="get">
<input placeholder="Quick search" aria-label="Quick search" type="search" name="q" id="search-box" />
<input type="submit" value="Go" />
</form>
</div>
|
</li>
<li class="right">
<label class="theme-selector-label">
Theme
<select class="theme-selector" oninput="activateTheme(this.value)">
<option value="auto" selected>Auto</option>
<option value="light">Light</option>
<option value="dark">Dark</option>
</select>
</label> |</li>
</ul>
</div>
<div class="document">
<div class="documentwrapper">
<div class="bodywrapper">
<div class="body" role="main">
<section id="why-is-python-installed-on-my-computer-faq">
<h1>“Why is Python Installed on my Computer?” FAQ<a class="headerlink" href="#why-is-python-installed-on-my-computer-faq" title="Link to this heading"></a></h1>
<section id="what-is-python">
<h2>What is Python?<a class="headerlink" href="#what-is-python" title="Link to this heading"></a></h2>
<p>Python is a programming language. Its used for many different applications.
Its used in some high schools and colleges as an introductory programming
language because Python is easy to learn, but its also used by professional
software developers at places such as Google, NASA, and Lucasfilm Ltd.</p>
<p>If you wish to learn more about Python, start with the <a class="reference external" href="https://wiki.python.org/moin/BeginnersGuide">Beginners Guide to
Python</a>.</p>
</section>
<section id="why-is-python-installed-on-my-machine">
<h2>Why is Python installed on my machine?<a class="headerlink" href="#why-is-python-installed-on-my-machine" title="Link to this heading"></a></h2>
<p>If you find Python installed on your system but dont remember installing it,
there are several possible ways it could have gotten there.</p>
<ul class="simple">
<li><p>Perhaps another user on the computer wanted to learn programming and installed
it; youll have to figure out whos been using the machine and might have
installed it.</p></li>
<li><p>A third-party application installed on the machine might have been written in
Python and included a Python installation. There are many such applications,
from GUI programs to network servers and administrative scripts.</p></li>
<li><p>Some Windows machines also have Python installed. At this writing were aware
of computers from Hewlett-Packard and Compaq that include Python. Apparently
some of HP/Compaqs administrative tools are written in Python.</p></li>
<li><p>Many Unix-compatible operating systems, such as macOS and some Linux
distributions, have Python installed by default; its included in the base
installation.</p></li>
</ul>
</section>
<section id="can-i-delete-python">
<h2>Can I delete Python?<a class="headerlink" href="#can-i-delete-python" title="Link to this heading"></a></h2>
<p>That depends on where Python came from.</p>
<p>If someone installed it deliberately, you can remove it without hurting
anything. On Windows, use the Add/Remove Programs icon in the Control Panel.</p>
<p>If Python was installed by a third-party application, you can also remove it,
but that application will no longer work. You should use that applications
uninstaller rather than removing Python directly.</p>
<p>If Python came with your operating system, removing it is not recommended. If
you remove it, whatever tools were written in Python will no longer run, and
some of them might be important to you. Reinstalling the whole system would
then be required to fix things again.</p>
</section>
</section>
<div class="clearer"></div>
</div>
</div>
</div>
<div class="sphinxsidebar" role="navigation" aria-label="Main">
<div class="sphinxsidebarwrapper">
<div>
<h3><a href="../contents.html">Table of Contents</a></h3>
<ul>
<li><a class="reference internal" href="#">“Why is Python Installed on my Computer?” FAQ</a><ul>
<li><a class="reference internal" href="#what-is-python">What is Python?</a></li>
<li><a class="reference internal" href="#why-is-python-installed-on-my-machine">Why is Python installed on my machine?</a></li>
<li><a class="reference internal" href="#can-i-delete-python">Can I delete Python?</a></li>
</ul>
</li>
</ul>
</div>
<div>
<h4>Previous topic</h4>
<p class="topless"><a href="gui.html"
title="previous chapter">Graphic User Interface FAQ</a></p>
</div>
<div>
<h4>Next topic</h4>
<p class="topless"><a href="../deprecations/index.html"
title="next chapter">Deprecations</a></p>
</div>
<div role="note" aria-label="source link">
<h3>This Page</h3>
<ul class="this-page-menu">
<li><a href="../bugs.html">Report a Bug</a></li>
<li>
<a href="https://github.com/python/cpython/blob/main/Doc/faq/installed.rst"
rel="nofollow">Show Source
</a>
</li>
</ul>
</div>
</div>
<div id="sidebarbutton" title="Collapse sidebar">
<span>«</span>
</div>
</div>
<div class="clearer"></div>
</div>
<div class="related" role="navigation" aria-label="Related">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="../genindex.html" title="General Index"
>index</a></li>
<li class="right" >
<a href="../py-modindex.html" title="Python Module Index"
>modules</a> |</li>
<li class="right" >
<a href="../deprecations/index.html" title="Deprecations"
>next</a> |</li>
<li class="right" >
<a href="gui.html" title="Graphic User Interface FAQ"
>previous</a> |</li>
<li><img src="../_static/py.svg" alt="Python logo" style="vertical-align: middle; margin-top: -1px"/></li>
<li><a href="https://www.python.org/">Python</a> &#187;</li>
<li class="switchers">
<div class="language_switcher_placeholder"></div>
<div class="version_switcher_placeholder"></div>
</li>
<li>
</li>
<li id="cpython-language-and-version">
<a href="../index.html">3.13.3 Documentation</a> &#187;
</li>
<li class="nav-item nav-item-1"><a href="index.html" >Python Frequently Asked Questions</a> &#187;</li>
<li class="nav-item nav-item-this"><a href="">“Why is Python Installed on my Computer?” FAQ</a></li>
<li class="right">
<div class="inline-search" role="search">
<form class="inline-search" action="../search.html" method="get">
<input placeholder="Quick search" aria-label="Quick search" type="search" name="q" id="search-box" />
<input type="submit" value="Go" />
</form>
</div>
|
</li>
<li class="right">
<label class="theme-selector-label">
Theme
<select class="theme-selector" oninput="activateTheme(this.value)">
<option value="auto" selected>Auto</option>
<option value="light">Light</option>
<option value="dark">Dark</option>
</select>
</label> |</li>
</ul>
</div>
<div class="footer">
&copy;
<a href="../copyright.html">
Copyright
</a>
2001-2025, Python Software Foundation.
<br />
This page is licensed under the Python Software Foundation License Version 2.
<br />
Examples, recipes, and other code in the documentation are additionally licensed under the Zero Clause BSD License.
<br />
See <a href="/license.html">History and License</a> for more information.<br />
<br />
The Python Software Foundation is a non-profit corporation.
<a href="https://www.python.org/psf/donations/">Please donate.</a>
<br />
<br />
Last updated on Apr 08, 2025 (14:33 UTC).
<a href="/bugs.html">Found a bug</a>?
<br />
Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 8.2.3.
</div>
</body>
</html>

View File

@@ -0,0 +1,993 @@
<!DOCTYPE html>
<html lang="en" data-content_root="../">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="viewport" content="width=device-width, initial-scale=1" />
<meta property="og:title" content="Library and Extension FAQ" />
<meta property="og:type" content="website" />
<meta property="og:url" content="https://docs.python.org/3/faq/library.html" />
<meta property="og:site_name" content="Python documentation" />
<meta property="og:description" content="Contents: Library and Extension FAQ- General Library Questions- How do I find a module or application to perform task X?, Where is the math.py (socket.py, regex.py, etc.) source file?, How do I mak..." />
<meta property="og:image" content="https://docs.python.org/3/_static/og-image.png" />
<meta property="og:image:alt" content="Python documentation" />
<meta name="description" content="Contents: Library and Extension FAQ- General Library Questions- How do I find a module or application to perform task X?, Where is the math.py (socket.py, regex.py, etc.) source file?, How do I mak..." />
<meta property="og:image:width" content="200">
<meta property="og:image:height" content="200">
<meta name="theme-color" content="#3776ab">
<title>Library and Extension FAQ &#8212; Python 3.13.3 documentation</title><meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" type="text/css" href="../_static/pygments.css?v=b86133f3" />
<link rel="stylesheet" type="text/css" href="../_static/pydoctheme.css?v=23252803" />
<link id="pygments_dark_css" media="(prefers-color-scheme: dark)" rel="stylesheet" type="text/css" href="../_static/pygments_dark.css?v=5349f25f" />
<script src="../_static/documentation_options.js?v=5d57ca2d"></script>
<script src="../_static/doctools.js?v=9bcbadda"></script>
<script src="../_static/sphinx_highlight.js?v=dc90522c"></script>
<script src="../_static/sidebar.js"></script>
<link rel="search" type="application/opensearchdescription+xml"
title="Search within Python 3.13.3 documentation"
href="../_static/opensearch.xml"/>
<link rel="author" title="About these documents" href="../about.html" />
<link rel="index" title="Index" href="../genindex.html" />
<link rel="search" title="Search" href="../search.html" />
<link rel="copyright" title="Copyright" href="../copyright.html" />
<link rel="next" title="Extending/Embedding FAQ" href="extending.html" />
<link rel="prev" title="Design and History FAQ" href="design.html" />
<link rel="canonical" href="https://docs.python.org/3/faq/library.html">
<style>
@media only screen {
table.full-width-table {
width: 100%;
}
}
</style>
<link rel="stylesheet" href="../_static/pydoctheme_dark.css" media="(prefers-color-scheme: dark)" id="pydoctheme_dark_css">
<link rel="shortcut icon" type="image/png" href="../_static/py.svg" />
<script type="text/javascript" src="../_static/copybutton.js"></script>
<script type="text/javascript" src="../_static/menu.js"></script>
<script type="text/javascript" src="../_static/search-focus.js"></script>
<script type="text/javascript" src="../_static/themetoggle.js"></script>
<script type="text/javascript" src="../_static/rtd_switcher.js"></script>
<meta name="readthedocs-addons-api-version" content="1">
</head>
<body>
<div class="mobile-nav">
<input type="checkbox" id="menuToggler" class="toggler__input" aria-controls="navigation"
aria-pressed="false" aria-expanded="false" role="button" aria-label="Menu" />
<nav class="nav-content" role="navigation">
<label for="menuToggler" class="toggler__label">
<span></span>
</label>
<span class="nav-items-wrapper">
<a href="https://www.python.org/" class="nav-logo">
<img src="../_static/py.svg" alt="Python logo"/>
</a>
<span class="version_switcher_placeholder"></span>
<form role="search" class="search" action="../search.html" method="get">
<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" class="search-icon">
<path fill-rule="nonzero" 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>
</svg>
<input placeholder="Quick search" aria-label="Quick search" type="search" name="q" />
<input type="submit" value="Go"/>
</form>
</span>
</nav>
<div class="menu-wrapper">
<nav class="menu" role="navigation" aria-label="main navigation">
<div class="language_switcher_placeholder"></div>
<label class="theme-selector-label">
Theme
<select class="theme-selector" oninput="activateTheme(this.value)">
<option value="auto" selected>Auto</option>
<option value="light">Light</option>
<option value="dark">Dark</option>
</select>
</label>
<div>
<h3><a href="../contents.html">Table of Contents</a></h3>
<ul>
<li><a class="reference internal" href="#">Library and Extension FAQ</a><ul>
<li><a class="reference internal" href="#general-library-questions">General Library Questions</a></li>
<li><a class="reference internal" href="#common-tasks">Common tasks</a></li>
<li><a class="reference internal" href="#threads">Threads</a></li>
<li><a class="reference internal" href="#input-and-output">Input and Output</a></li>
<li><a class="reference internal" href="#network-internet-programming">Network/Internet Programming</a></li>
<li><a class="reference internal" href="#databases">Databases</a></li>
<li><a class="reference internal" href="#mathematics-and-numerics">Mathematics and Numerics</a></li>
</ul>
</li>
</ul>
</div>
<div>
<h4>Previous topic</h4>
<p class="topless"><a href="design.html"
title="previous chapter">Design and History FAQ</a></p>
</div>
<div>
<h4>Next topic</h4>
<p class="topless"><a href="extending.html"
title="next chapter">Extending/Embedding FAQ</a></p>
</div>
<div role="note" aria-label="source link">
<h3>This Page</h3>
<ul class="this-page-menu">
<li><a href="../bugs.html">Report a Bug</a></li>
<li>
<a href="https://github.com/python/cpython/blob/main/Doc/faq/library.rst"
rel="nofollow">Show Source
</a>
</li>
</ul>
</div>
</nav>
</div>
</div>
<div class="related" role="navigation" aria-label="Related">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="../genindex.html" title="General Index"
accesskey="I">index</a></li>
<li class="right" >
<a href="../py-modindex.html" title="Python Module Index"
>modules</a> |</li>
<li class="right" >
<a href="extending.html" title="Extending/Embedding FAQ"
accesskey="N">next</a> |</li>
<li class="right" >
<a href="design.html" title="Design and History FAQ"
accesskey="P">previous</a> |</li>
<li><img src="../_static/py.svg" alt="Python logo" style="vertical-align: middle; margin-top: -1px"/></li>
<li><a href="https://www.python.org/">Python</a> &#187;</li>
<li class="switchers">
<div class="language_switcher_placeholder"></div>
<div class="version_switcher_placeholder"></div>
</li>
<li>
</li>
<li id="cpython-language-and-version">
<a href="../index.html">3.13.3 Documentation</a> &#187;
</li>
<li class="nav-item nav-item-1"><a href="index.html" accesskey="U">Python Frequently Asked Questions</a> &#187;</li>
<li class="nav-item nav-item-this"><a href="">Library and Extension FAQ</a></li>
<li class="right">
<div class="inline-search" role="search">
<form class="inline-search" action="../search.html" method="get">
<input placeholder="Quick search" aria-label="Quick search" type="search" name="q" id="search-box" />
<input type="submit" value="Go" />
</form>
</div>
|
</li>
<li class="right">
<label class="theme-selector-label">
Theme
<select class="theme-selector" oninput="activateTheme(this.value)">
<option value="auto" selected>Auto</option>
<option value="light">Light</option>
<option value="dark">Dark</option>
</select>
</label> |</li>
</ul>
</div>
<div class="document">
<div class="documentwrapper">
<div class="bodywrapper">
<div class="body" role="main">
<section id="library-and-extension-faq">
<h1><a class="toc-backref" href="#id1" role="doc-backlink">Library and Extension FAQ</a><a class="headerlink" href="#library-and-extension-faq" title="Link to this heading"></a></h1>
<nav class="contents" id="contents">
<p class="topic-title">Contents</p>
<ul class="simple">
<li><p><a class="reference internal" href="#library-and-extension-faq" id="id1">Library and Extension FAQ</a></p>
<ul>
<li><p><a class="reference internal" href="#general-library-questions" id="id2">General Library Questions</a></p>
<ul>
<li><p><a class="reference internal" href="#how-do-i-find-a-module-or-application-to-perform-task-x" id="id3">How do I find a module or application to perform task X?</a></p></li>
<li><p><a class="reference internal" href="#where-is-the-math-py-socket-py-regex-py-etc-source-file" id="id4">Where is the math.py (socket.py, regex.py, etc.) source file?</a></p></li>
<li><p><a class="reference internal" href="#how-do-i-make-a-python-script-executable-on-unix" id="id5">How do I make a Python script executable on Unix?</a></p></li>
<li><p><a class="reference internal" href="#is-there-a-curses-termcap-package-for-python" id="id6">Is there a curses/termcap package for Python?</a></p></li>
<li><p><a class="reference internal" href="#is-there-an-equivalent-to-c-s-onexit-in-python" id="id7">Is there an equivalent to Cs onexit() in Python?</a></p></li>
<li><p><a class="reference internal" href="#why-don-t-my-signal-handlers-work" id="id8">Why dont my signal handlers work?</a></p></li>
</ul>
</li>
<li><p><a class="reference internal" href="#common-tasks" id="id9">Common tasks</a></p>
<ul>
<li><p><a class="reference internal" href="#how-do-i-test-a-python-program-or-component" id="id10">How do I test a Python program or component?</a></p></li>
<li><p><a class="reference internal" href="#how-do-i-create-documentation-from-doc-strings" id="id11">How do I create documentation from doc strings?</a></p></li>
<li><p><a class="reference internal" href="#how-do-i-get-a-single-keypress-at-a-time" id="id12">How do I get a single keypress at a time?</a></p></li>
</ul>
</li>
<li><p><a class="reference internal" href="#threads" id="id13">Threads</a></p>
<ul>
<li><p><a class="reference internal" href="#how-do-i-program-using-threads" id="id14">How do I program using threads?</a></p></li>
<li><p><a class="reference internal" href="#none-of-my-threads-seem-to-run-why" id="id15">None of my threads seem to run: why?</a></p></li>
<li><p><a class="reference internal" href="#how-do-i-parcel-out-work-among-a-bunch-of-worker-threads" id="id16">How do I parcel out work among a bunch of worker threads?</a></p></li>
<li><p><a class="reference internal" href="#what-kinds-of-global-value-mutation-are-thread-safe" id="id17">What kinds of global value mutation are thread-safe?</a></p></li>
<li><p><a class="reference internal" href="#can-t-we-get-rid-of-the-global-interpreter-lock" id="id18">Cant we get rid of the Global Interpreter Lock?</a></p></li>
</ul>
</li>
<li><p><a class="reference internal" href="#input-and-output" id="id19">Input and Output</a></p>
<ul>
<li><p><a class="reference internal" href="#how-do-i-delete-a-file-and-other-file-questions" id="id20">How do I delete a file? (And other file questions…)</a></p></li>
<li><p><a class="reference internal" href="#how-do-i-copy-a-file" id="id21">How do I copy a file?</a></p></li>
<li><p><a class="reference internal" href="#how-do-i-read-or-write-binary-data" id="id22">How do I read (or write) binary data?</a></p></li>
<li><p><a class="reference internal" href="#i-can-t-seem-to-use-os-read-on-a-pipe-created-with-os-popen-why" id="id23">I cant seem to use os.read() on a pipe created with os.popen(); why?</a></p></li>
<li><p><a class="reference internal" href="#how-do-i-access-the-serial-rs232-port" id="id24">How do I access the serial (RS232) port?</a></p></li>
<li><p><a class="reference internal" href="#why-doesn-t-closing-sys-stdout-stdin-stderr-really-close-it" id="id25">Why doesnt closing sys.stdout (stdin, stderr) really close it?</a></p></li>
</ul>
</li>
<li><p><a class="reference internal" href="#network-internet-programming" id="id26">Network/Internet Programming</a></p>
<ul>
<li><p><a class="reference internal" href="#what-www-tools-are-there-for-python" id="id27">What WWW tools are there for Python?</a></p></li>
<li><p><a class="reference internal" href="#what-module-should-i-use-to-help-with-generating-html" id="id28">What module should I use to help with generating HTML?</a></p></li>
<li><p><a class="reference internal" href="#how-do-i-send-mail-from-a-python-script" id="id29">How do I send mail from a Python script?</a></p></li>
<li><p><a class="reference internal" href="#how-do-i-avoid-blocking-in-the-connect-method-of-a-socket" id="id30">How do I avoid blocking in the connect() method of a socket?</a></p></li>
</ul>
</li>
<li><p><a class="reference internal" href="#databases" id="id31">Databases</a></p>
<ul>
<li><p><a class="reference internal" href="#are-there-any-interfaces-to-database-packages-in-python" id="id32">Are there any interfaces to database packages in Python?</a></p></li>
<li><p><a class="reference internal" href="#how-do-you-implement-persistent-objects-in-python" id="id33">How do you implement persistent objects in Python?</a></p></li>
</ul>
</li>
<li><p><a class="reference internal" href="#mathematics-and-numerics" id="id34">Mathematics and Numerics</a></p>
<ul>
<li><p><a class="reference internal" href="#how-do-i-generate-random-numbers-in-python" id="id35">How do I generate random numbers in Python?</a></p></li>
</ul>
</li>
</ul>
</li>
</ul>
</nav>
<section id="general-library-questions">
<h2><a class="toc-backref" href="#id2" role="doc-backlink">General Library Questions</a><a class="headerlink" href="#general-library-questions" title="Link to this heading"></a></h2>
<section id="how-do-i-find-a-module-or-application-to-perform-task-x">
<h3><a class="toc-backref" href="#id3" role="doc-backlink">How do I find a module or application to perform task X?</a><a class="headerlink" href="#how-do-i-find-a-module-or-application-to-perform-task-x" title="Link to this heading"></a></h3>
<p>Check <a class="reference internal" href="../library/index.html#library-index"><span class="std std-ref">the Library Reference</span></a> to see if theres a relevant
standard library module. (Eventually youll learn whats in the standard
library and will be able to skip this step.)</p>
<p>For third-party packages, search the <a class="reference external" href="https://pypi.org">Python Package Index</a> or try <a class="reference external" href="https://www.google.com">Google</a> or
another web search engine. Searching for “Python” plus a keyword or two for
your topic of interest will usually find something helpful.</p>
</section>
<section id="where-is-the-math-py-socket-py-regex-py-etc-source-file">
<h3><a class="toc-backref" href="#id4" role="doc-backlink">Where is the math.py (socket.py, regex.py, etc.) source file?</a><a class="headerlink" href="#where-is-the-math-py-socket-py-regex-py-etc-source-file" title="Link to this heading"></a></h3>
<p>If you cant find a source file for a module it may be a built-in or
dynamically loaded module implemented in C, C++ or other compiled language.
In this case you may not have the source file or it may be something like
<code class="file docutils literal notranslate"><span class="pre">mathmodule.c</span></code>, somewhere in a C source directory (not on the Python Path).</p>
<p>There are (at least) three kinds of modules in Python:</p>
<ol class="arabic">
<li><p>modules written in Python (.py);</p></li>
<li><p>modules written in C and dynamically loaded (.dll, .pyd, .so, .sl, etc);</p></li>
<li><p>modules written in C and linked with the interpreter; to get a list of these,
type:</p>
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="kn">import</span><span class="w"> </span><span class="nn">sys</span>
<span class="nb">print</span><span class="p">(</span><span class="n">sys</span><span class="o">.</span><span class="n">builtin_module_names</span><span class="p">)</span>
</pre></div>
</div>
</li>
</ol>
</section>
<section id="how-do-i-make-a-python-script-executable-on-unix">
<h3><a class="toc-backref" href="#id5" role="doc-backlink">How do I make a Python script executable on Unix?</a><a class="headerlink" href="#how-do-i-make-a-python-script-executable-on-unix" title="Link to this heading"></a></h3>
<p>You need to do two things: the script files mode must be executable and the
first line must begin with <code class="docutils literal notranslate"><span class="pre">#!</span></code> followed by the path of the Python
interpreter.</p>
<p>The first is done by executing <code class="docutils literal notranslate"><span class="pre">chmod</span> <span class="pre">+x</span> <span class="pre">scriptfile</span></code> or perhaps <code class="docutils literal notranslate"><span class="pre">chmod</span> <span class="pre">755</span>
<span class="pre">scriptfile</span></code>.</p>
<p>The second can be done in a number of ways. The most straightforward way is to
write</p>
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="ch">#!/usr/local/bin/python</span>
</pre></div>
</div>
<p>as the very first line of your file, using the pathname for where the Python
interpreter is installed on your platform.</p>
<p>If you would like the script to be independent of where the Python interpreter
lives, you can use the <strong class="program">env</strong> program. Almost all Unix variants support
the following, assuming the Python interpreter is in a directory on the users
<span class="target" id="index-0"></span><code class="xref std std-envvar docutils literal notranslate"><span class="pre">PATH</span></code>:</p>
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="ch">#!/usr/bin/env python</span>
</pre></div>
</div>
<p><em>Dont</em> do this for CGI scripts. The <span class="target" id="index-1"></span><code class="xref std std-envvar docutils literal notranslate"><span class="pre">PATH</span></code> variable for CGI scripts is
often very minimal, so you need to use the actual absolute pathname of the
interpreter.</p>
<p>Occasionally, a users environment is so full that the <strong class="program">/usr/bin/env</strong>
program fails; or theres no env program at all. In that case, you can try the
following hack (due to Alex Rezinsky):</p>
<div class="highlight-sh notranslate"><div class="highlight"><pre><span></span><span class="ch">#! /bin/sh</span>
<span class="s2">&quot;&quot;&quot;:&quot;</span>
<span class="nb">exec</span><span class="w"> </span>python<span class="w"> </span><span class="nv">$0</span><span class="w"> </span><span class="si">${</span><span class="nv">1</span><span class="p">+</span><span class="s2">&quot;</span><span class="nv">$@</span><span class="s2">&quot;</span><span class="si">}</span>
<span class="s2">&quot;&quot;&quot;</span>
</pre></div>
</div>
<p>The minor disadvantage is that this defines the scripts __doc__ string.
However, you can fix that by adding</p>
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="vm">__doc__</span> <span class="o">=</span> <span class="s2">&quot;&quot;&quot;...Whatever...&quot;&quot;&quot;</span>
</pre></div>
</div>
</section>
<section id="is-there-a-curses-termcap-package-for-python">
<h3><a class="toc-backref" href="#id6" role="doc-backlink">Is there a curses/termcap package for Python?</a><a class="headerlink" href="#is-there-a-curses-termcap-package-for-python" title="Link to this heading"></a></h3>
<p>For Unix variants: The standard Python source distribution comes with a curses
module in the <a class="extlink-source reference external" href="https://github.com/python/cpython/tree/3.13/Modules">Modules</a> subdirectory, though its not compiled by default.
(Note that this is not available in the Windows distribution there is no
curses module for Windows.)</p>
<p>The <a class="reference internal" href="../library/curses.html#module-curses" title="curses: An interface to the curses library, providing portable terminal handling. (Unix)"><code class="xref py py-mod docutils literal notranslate"><span class="pre">curses</span></code></a> module supports basic curses features as well as many additional
functions from ncurses and SYSV curses such as colour, alternative character set
support, pads, and mouse support. This means the module isnt compatible with
operating systems that only have BSD curses, but there dont seem to be any
currently maintained OSes that fall into this category.</p>
</section>
<section id="is-there-an-equivalent-to-c-s-onexit-in-python">
<h3><a class="toc-backref" href="#id7" role="doc-backlink">Is there an equivalent to Cs onexit() in Python?</a><a class="headerlink" href="#is-there-an-equivalent-to-c-s-onexit-in-python" title="Link to this heading"></a></h3>
<p>The <a class="reference internal" href="../library/atexit.html#module-atexit" title="atexit: Register and execute cleanup functions."><code class="xref py py-mod docutils literal notranslate"><span class="pre">atexit</span></code></a> module provides a register function that is similar to Cs
<code class="xref c c-func docutils literal notranslate"><span class="pre">onexit()</span></code>.</p>
</section>
<section id="why-don-t-my-signal-handlers-work">
<h3><a class="toc-backref" href="#id8" role="doc-backlink">Why dont my signal handlers work?</a><a class="headerlink" href="#why-don-t-my-signal-handlers-work" title="Link to this heading"></a></h3>
<p>The most common problem is that the signal handler is declared with the wrong
argument list. It is called as</p>
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="n">handler</span><span class="p">(</span><span class="n">signum</span><span class="p">,</span> <span class="n">frame</span><span class="p">)</span>
</pre></div>
</div>
<p>so it should be declared with two parameters:</p>
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="k">def</span><span class="w"> </span><span class="nf">handler</span><span class="p">(</span><span class="n">signum</span><span class="p">,</span> <span class="n">frame</span><span class="p">):</span>
<span class="o">...</span>
</pre></div>
</div>
</section>
</section>
<section id="common-tasks">
<h2><a class="toc-backref" href="#id9" role="doc-backlink">Common tasks</a><a class="headerlink" href="#common-tasks" title="Link to this heading"></a></h2>
<section id="how-do-i-test-a-python-program-or-component">
<h3><a class="toc-backref" href="#id10" role="doc-backlink">How do I test a Python program or component?</a><a class="headerlink" href="#how-do-i-test-a-python-program-or-component" title="Link to this heading"></a></h3>
<p>Python comes with two testing frameworks. The <a class="reference internal" href="../library/doctest.html#module-doctest" title="doctest: Test pieces of code within docstrings."><code class="xref py py-mod docutils literal notranslate"><span class="pre">doctest</span></code></a> module finds
examples in the docstrings for a module and runs them, comparing the output with
the expected output given in the docstring.</p>
<p>The <a class="reference internal" href="../library/unittest.html#module-unittest" title="unittest: Unit testing framework for Python."><code class="xref py py-mod docutils literal notranslate"><span class="pre">unittest</span></code></a> module is a fancier testing framework modelled on Java and
Smalltalk testing frameworks.</p>
<p>To make testing easier, you should use good modular design in your program.
Your program should have almost all functionality
encapsulated in either functions or class methods and this sometimes has the
surprising and delightful effect of making the program run faster (because local
variable accesses are faster than global accesses). Furthermore the program
should avoid depending on mutating global variables, since this makes testing
much more difficult to do.</p>
<p>The “global main logic” of your program may be as simple as</p>
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="k">if</span> <span class="vm">__name__</span> <span class="o">==</span> <span class="s2">&quot;__main__&quot;</span><span class="p">:</span>
<span class="n">main_logic</span><span class="p">()</span>
</pre></div>
</div>
<p>at the bottom of the main module of your program.</p>
<p>Once your program is organized as a tractable collection of function and class
behaviours, you should write test functions that exercise the behaviours. A
test suite that automates a sequence of tests can be associated with each module.
This sounds like a lot of work, but since Python is so terse and flexible its
surprisingly easy. You can make coding much more pleasant and fun by writing
your test functions in parallel with the “production code”, since this makes it
easy to find bugs and even design flaws earlier.</p>
<p>“Support modules” that are not intended to be the main module of a program may
include a self-test of the module.</p>
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="k">if</span> <span class="vm">__name__</span> <span class="o">==</span> <span class="s2">&quot;__main__&quot;</span><span class="p">:</span>
<span class="n">self_test</span><span class="p">()</span>
</pre></div>
</div>
<p>Even programs that interact with complex external interfaces may be tested when
the external interfaces are unavailable by using “fake” interfaces implemented
in Python.</p>
</section>
<section id="how-do-i-create-documentation-from-doc-strings">
<h3><a class="toc-backref" href="#id11" role="doc-backlink">How do I create documentation from doc strings?</a><a class="headerlink" href="#how-do-i-create-documentation-from-doc-strings" title="Link to this heading"></a></h3>
<p>The <a class="reference internal" href="../library/pydoc.html#module-pydoc" title="pydoc: Documentation generator and online help system."><code class="xref py py-mod docutils literal notranslate"><span class="pre">pydoc</span></code></a> module can create HTML from the doc strings in your Python
source code. An alternative for creating API documentation purely from
docstrings is <a class="reference external" href="https://epydoc.sourceforge.net/">epydoc</a>. <a class="reference external" href="https://www.sphinx-doc.org">Sphinx</a> can also include docstring content.</p>
</section>
<section id="how-do-i-get-a-single-keypress-at-a-time">
<h3><a class="toc-backref" href="#id12" role="doc-backlink">How do I get a single keypress at a time?</a><a class="headerlink" href="#how-do-i-get-a-single-keypress-at-a-time" title="Link to this heading"></a></h3>
<p>For Unix variants there are several solutions. Its straightforward to do this
using curses, but curses is a fairly large module to learn.</p>
</section>
</section>
<section id="threads">
<h2><a class="toc-backref" href="#id13" role="doc-backlink">Threads</a><a class="headerlink" href="#threads" title="Link to this heading"></a></h2>
<section id="how-do-i-program-using-threads">
<h3><a class="toc-backref" href="#id14" role="doc-backlink">How do I program using threads?</a><a class="headerlink" href="#how-do-i-program-using-threads" title="Link to this heading"></a></h3>
<p>Be sure to use the <a class="reference internal" href="../library/threading.html#module-threading" title="threading: Thread-based parallelism."><code class="xref py py-mod docutils literal notranslate"><span class="pre">threading</span></code></a> module and not the <a class="reference internal" href="../library/_thread.html#module-_thread" title="_thread: Low-level threading API."><code class="xref py py-mod docutils literal notranslate"><span class="pre">_thread</span></code></a> module.
The <a class="reference internal" href="../library/threading.html#module-threading" title="threading: Thread-based parallelism."><code class="xref py py-mod docutils literal notranslate"><span class="pre">threading</span></code></a> module builds convenient abstractions on top of the
low-level primitives provided by the <a class="reference internal" href="../library/_thread.html#module-_thread" title="_thread: Low-level threading API."><code class="xref py py-mod docutils literal notranslate"><span class="pre">_thread</span></code></a> module.</p>
</section>
<section id="none-of-my-threads-seem-to-run-why">
<h3><a class="toc-backref" href="#id15" role="doc-backlink">None of my threads seem to run: why?</a><a class="headerlink" href="#none-of-my-threads-seem-to-run-why" title="Link to this heading"></a></h3>
<p>As soon as the main thread exits, all threads are killed. Your main thread is
running too quickly, giving the threads no time to do any work.</p>
<p>A simple fix is to add a sleep to the end of the program thats long enough for
all the threads to finish:</p>
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="kn">import</span><span class="w"> </span><span class="nn">threading</span><span class="o">,</span><span class="w"> </span><span class="nn">time</span>
<span class="k">def</span><span class="w"> </span><span class="nf">thread_task</span><span class="p">(</span><span class="n">name</span><span class="p">,</span> <span class="n">n</span><span class="p">):</span>
<span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="n">n</span><span class="p">):</span>
<span class="nb">print</span><span class="p">(</span><span class="n">name</span><span class="p">,</span> <span class="n">i</span><span class="p">)</span>
<span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">10</span><span class="p">):</span>
<span class="n">T</span> <span class="o">=</span> <span class="n">threading</span><span class="o">.</span><span class="n">Thread</span><span class="p">(</span><span class="n">target</span><span class="o">=</span><span class="n">thread_task</span><span class="p">,</span> <span class="n">args</span><span class="o">=</span><span class="p">(</span><span class="nb">str</span><span class="p">(</span><span class="n">i</span><span class="p">),</span> <span class="n">i</span><span class="p">))</span>
<span class="n">T</span><span class="o">.</span><span class="n">start</span><span class="p">()</span>
<span class="n">time</span><span class="o">.</span><span class="n">sleep</span><span class="p">(</span><span class="mi">10</span><span class="p">)</span> <span class="c1"># &lt;---------------------------!</span>
</pre></div>
</div>
<p>But now (on many platforms) the threads dont run in parallel, but appear to run
sequentially, one at a time! The reason is that the OS thread scheduler doesnt
start a new thread until the previous thread is blocked.</p>
<p>A simple fix is to add a tiny sleep to the start of the run function:</p>
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="k">def</span><span class="w"> </span><span class="nf">thread_task</span><span class="p">(</span><span class="n">name</span><span class="p">,</span> <span class="n">n</span><span class="p">):</span>
<span class="n">time</span><span class="o">.</span><span class="n">sleep</span><span class="p">(</span><span class="mf">0.001</span><span class="p">)</span> <span class="c1"># &lt;--------------------!</span>
<span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="n">n</span><span class="p">):</span>
<span class="nb">print</span><span class="p">(</span><span class="n">name</span><span class="p">,</span> <span class="n">i</span><span class="p">)</span>
<span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">10</span><span class="p">):</span>
<span class="n">T</span> <span class="o">=</span> <span class="n">threading</span><span class="o">.</span><span class="n">Thread</span><span class="p">(</span><span class="n">target</span><span class="o">=</span><span class="n">thread_task</span><span class="p">,</span> <span class="n">args</span><span class="o">=</span><span class="p">(</span><span class="nb">str</span><span class="p">(</span><span class="n">i</span><span class="p">),</span> <span class="n">i</span><span class="p">))</span>
<span class="n">T</span><span class="o">.</span><span class="n">start</span><span class="p">()</span>
<span class="n">time</span><span class="o">.</span><span class="n">sleep</span><span class="p">(</span><span class="mi">10</span><span class="p">)</span>
</pre></div>
</div>
<p>Instead of trying to guess a good delay value for <a class="reference internal" href="../library/time.html#time.sleep" title="time.sleep"><code class="xref py py-func docutils literal notranslate"><span class="pre">time.sleep()</span></code></a>,
its better to use some kind of semaphore mechanism. One idea is to use the
<a class="reference internal" href="../library/queue.html#module-queue" title="queue: A synchronized queue class."><code class="xref py py-mod docutils literal notranslate"><span class="pre">queue</span></code></a> module to create a queue object, let each thread append a token to
the queue when it finishes, and let the main thread read as many tokens from the
queue as there are threads.</p>
</section>
<section id="how-do-i-parcel-out-work-among-a-bunch-of-worker-threads">
<h3><a class="toc-backref" href="#id16" role="doc-backlink">How do I parcel out work among a bunch of worker threads?</a><a class="headerlink" href="#how-do-i-parcel-out-work-among-a-bunch-of-worker-threads" title="Link to this heading"></a></h3>
<p>The easiest way is to use the <a class="reference internal" href="../library/concurrent.futures.html#module-concurrent.futures" title="concurrent.futures: Execute computations concurrently using threads or processes."><code class="xref py py-mod docutils literal notranslate"><span class="pre">concurrent.futures</span></code></a> module,
especially the <a class="reference internal" href="../library/concurrent.futures.html#concurrent.futures.ThreadPoolExecutor" title="concurrent.futures.ThreadPoolExecutor"><code class="xref py py-mod docutils literal notranslate"><span class="pre">ThreadPoolExecutor</span></code></a> class.</p>
<p>Or, if you want fine control over the dispatching algorithm, you can write
your own logic manually. Use the <a class="reference internal" href="../library/queue.html#module-queue" title="queue: A synchronized queue class."><code class="xref py py-mod docutils literal notranslate"><span class="pre">queue</span></code></a> module to create a queue
containing a list of jobs. The <a class="reference internal" href="../library/queue.html#queue.Queue" title="queue.Queue"><code class="xref py py-class docutils literal notranslate"><span class="pre">Queue</span></code></a> class maintains a
list of objects and has a <code class="docutils literal notranslate"><span class="pre">.put(obj)</span></code> method that adds items to the queue and
a <code class="docutils literal notranslate"><span class="pre">.get()</span></code> method to return them. The class will take care of the locking
necessary to ensure that each job is handed out exactly once.</p>
<p>Heres a trivial example:</p>
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="kn">import</span><span class="w"> </span><span class="nn">threading</span><span class="o">,</span><span class="w"> </span><span class="nn">queue</span><span class="o">,</span><span class="w"> </span><span class="nn">time</span>
<span class="c1"># The worker thread gets jobs off the queue. When the queue is empty, it</span>
<span class="c1"># assumes there will be no more work and exits.</span>
<span class="c1"># (Realistically workers will run until terminated.)</span>
<span class="k">def</span><span class="w"> </span><span class="nf">worker</span><span class="p">():</span>
<span class="nb">print</span><span class="p">(</span><span class="s1">&#39;Running worker&#39;</span><span class="p">)</span>
<span class="n">time</span><span class="o">.</span><span class="n">sleep</span><span class="p">(</span><span class="mf">0.1</span><span class="p">)</span>
<span class="k">while</span> <span class="kc">True</span><span class="p">:</span>
<span class="k">try</span><span class="p">:</span>
<span class="n">arg</span> <span class="o">=</span> <span class="n">q</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">block</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
<span class="k">except</span> <span class="n">queue</span><span class="o">.</span><span class="n">Empty</span><span class="p">:</span>
<span class="nb">print</span><span class="p">(</span><span class="s1">&#39;Worker&#39;</span><span class="p">,</span> <span class="n">threading</span><span class="o">.</span><span class="n">current_thread</span><span class="p">(),</span> <span class="n">end</span><span class="o">=</span><span class="s1">&#39; &#39;</span><span class="p">)</span>
<span class="nb">print</span><span class="p">(</span><span class="s1">&#39;queue empty&#39;</span><span class="p">)</span>
<span class="k">break</span>
<span class="k">else</span><span class="p">:</span>
<span class="nb">print</span><span class="p">(</span><span class="s1">&#39;Worker&#39;</span><span class="p">,</span> <span class="n">threading</span><span class="o">.</span><span class="n">current_thread</span><span class="p">(),</span> <span class="n">end</span><span class="o">=</span><span class="s1">&#39; &#39;</span><span class="p">)</span>
<span class="nb">print</span><span class="p">(</span><span class="s1">&#39;running with argument&#39;</span><span class="p">,</span> <span class="n">arg</span><span class="p">)</span>
<span class="n">time</span><span class="o">.</span><span class="n">sleep</span><span class="p">(</span><span class="mf">0.5</span><span class="p">)</span>
<span class="c1"># Create queue</span>
<span class="n">q</span> <span class="o">=</span> <span class="n">queue</span><span class="o">.</span><span class="n">Queue</span><span class="p">()</span>
<span class="c1"># Start a pool of 5 workers</span>
<span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">5</span><span class="p">):</span>
<span class="n">t</span> <span class="o">=</span> <span class="n">threading</span><span class="o">.</span><span class="n">Thread</span><span class="p">(</span><span class="n">target</span><span class="o">=</span><span class="n">worker</span><span class="p">,</span> <span class="n">name</span><span class="o">=</span><span class="s1">&#39;worker </span><span class="si">%i</span><span class="s1">&#39;</span> <span class="o">%</span> <span class="p">(</span><span class="n">i</span><span class="o">+</span><span class="mi">1</span><span class="p">))</span>
<span class="n">t</span><span class="o">.</span><span class="n">start</span><span class="p">()</span>
<span class="c1"># Begin adding work to the queue</span>
<span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">50</span><span class="p">):</span>
<span class="n">q</span><span class="o">.</span><span class="n">put</span><span class="p">(</span><span class="n">i</span><span class="p">)</span>
<span class="c1"># Give threads time to run</span>
<span class="nb">print</span><span class="p">(</span><span class="s1">&#39;Main thread sleeping&#39;</span><span class="p">)</span>
<span class="n">time</span><span class="o">.</span><span class="n">sleep</span><span class="p">(</span><span class="mi">5</span><span class="p">)</span>
</pre></div>
</div>
<p>When run, this will produce the following output:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>Running worker
Running worker
Running worker
Running worker
Running worker
Main thread sleeping
Worker &lt;Thread(worker 1, started 130283832797456)&gt; running with argument 0
Worker &lt;Thread(worker 2, started 130283824404752)&gt; running with argument 1
Worker &lt;Thread(worker 3, started 130283816012048)&gt; running with argument 2
Worker &lt;Thread(worker 4, started 130283807619344)&gt; running with argument 3
Worker &lt;Thread(worker 5, started 130283799226640)&gt; running with argument 4
Worker &lt;Thread(worker 1, started 130283832797456)&gt; running with argument 5
...
</pre></div>
</div>
<p>Consult the modules documentation for more details; the <a class="reference internal" href="../library/queue.html#queue.Queue" title="queue.Queue"><code class="xref py py-class docutils literal notranslate"><span class="pre">Queue</span></code></a>
class provides a featureful interface.</p>
</section>
<section id="what-kinds-of-global-value-mutation-are-thread-safe">
<h3><a class="toc-backref" href="#id17" role="doc-backlink">What kinds of global value mutation are thread-safe?</a><a class="headerlink" href="#what-kinds-of-global-value-mutation-are-thread-safe" title="Link to this heading"></a></h3>
<p>A <a class="reference internal" href="../glossary.html#term-global-interpreter-lock"><span class="xref std std-term">global interpreter lock</span></a> (GIL) is used internally to ensure that only one
thread runs in the Python VM at a time. In general, Python offers to switch
among threads only between bytecode instructions; how frequently it switches can
be set via <a class="reference internal" href="../library/sys.html#sys.setswitchinterval" title="sys.setswitchinterval"><code class="xref py py-func docutils literal notranslate"><span class="pre">sys.setswitchinterval()</span></code></a>. Each bytecode instruction and
therefore all the C implementation code reached from each instruction is
therefore atomic from the point of view of a Python program.</p>
<p>In theory, this means an exact accounting requires an exact understanding of the
PVM bytecode implementation. In practice, it means that operations on shared
variables of built-in data types (ints, lists, dicts, etc) that “look atomic”
really are.</p>
<p>For example, the following operations are all atomic (L, L1, L2 are lists, D,
D1, D2 are dicts, x, y are objects, i, j are ints):</p>
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="n">L</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">x</span><span class="p">)</span>
<span class="n">L1</span><span class="o">.</span><span class="n">extend</span><span class="p">(</span><span class="n">L2</span><span class="p">)</span>
<span class="n">x</span> <span class="o">=</span> <span class="n">L</span><span class="p">[</span><span class="n">i</span><span class="p">]</span>
<span class="n">x</span> <span class="o">=</span> <span class="n">L</span><span class="o">.</span><span class="n">pop</span><span class="p">()</span>
<span class="n">L1</span><span class="p">[</span><span class="n">i</span><span class="p">:</span><span class="n">j</span><span class="p">]</span> <span class="o">=</span> <span class="n">L2</span>
<span class="n">L</span><span class="o">.</span><span class="n">sort</span><span class="p">()</span>
<span class="n">x</span> <span class="o">=</span> <span class="n">y</span>
<span class="n">x</span><span class="o">.</span><span class="n">field</span> <span class="o">=</span> <span class="n">y</span>
<span class="n">D</span><span class="p">[</span><span class="n">x</span><span class="p">]</span> <span class="o">=</span> <span class="n">y</span>
<span class="n">D1</span><span class="o">.</span><span class="n">update</span><span class="p">(</span><span class="n">D2</span><span class="p">)</span>
<span class="n">D</span><span class="o">.</span><span class="n">keys</span><span class="p">()</span>
</pre></div>
</div>
<p>These arent:</p>
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="n">i</span> <span class="o">=</span> <span class="n">i</span><span class="o">+</span><span class="mi">1</span>
<span class="n">L</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">L</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">])</span>
<span class="n">L</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">=</span> <span class="n">L</span><span class="p">[</span><span class="n">j</span><span class="p">]</span>
<span class="n">D</span><span class="p">[</span><span class="n">x</span><span class="p">]</span> <span class="o">=</span> <span class="n">D</span><span class="p">[</span><span class="n">x</span><span class="p">]</span> <span class="o">+</span> <span class="mi">1</span>
</pre></div>
</div>
<p>Operations that replace other objects may invoke those other objects
<a class="reference internal" href="../reference/datamodel.html#object.__del__" title="object.__del__"><code class="xref py py-meth docutils literal notranslate"><span class="pre">__del__()</span></code></a> method when their reference count reaches zero, and that can
affect things. This is especially true for the mass updates to dictionaries and
lists. When in doubt, use a mutex!</p>
</section>
<section id="can-t-we-get-rid-of-the-global-interpreter-lock">
<h3><a class="toc-backref" href="#id18" role="doc-backlink">Cant we get rid of the Global Interpreter Lock?</a><a class="headerlink" href="#can-t-we-get-rid-of-the-global-interpreter-lock" title="Link to this heading"></a></h3>
<p>The <a class="reference internal" href="../glossary.html#term-global-interpreter-lock"><span class="xref std std-term">global interpreter lock</span></a> (GIL) is often seen as a hindrance to Pythons
deployment on high-end multiprocessor server machines, because a multi-threaded
Python program effectively only uses one CPU, due to the insistence that
(almost) all Python code can only run while the GIL is held.</p>
<p>With the approval of <span class="target" id="index-2"></span><a class="pep reference external" href="https://peps.python.org/pep-0703/"><strong>PEP 703</strong></a> work is now underway to remove the GIL from the
CPython implementation of Python. Initially it will be implemented as an
optional compiler flag when building the interpreter, and so separate
builds will be available with and without the GIL. Long-term, the hope is
to settle on a single build, once the performance implications of removing the
GIL are fully understood. Python 3.13 is likely to be the first release
containing this work, although it may not be completely functional in this
release.</p>
<p>The current work to remove the GIL is based on a
<a class="reference external" href="https://github.com/colesbury/nogil">fork of Python 3.9 with the GIL removed</a>
by Sam Gross.
Prior to that,
in the days of Python 1.5, Greg Stein actually implemented a comprehensive
patch set (the “free threading” patches) that removed the GIL and replaced it
with fine-grained locking. Adam Olsen did a similar experiment
in his <a class="reference external" href="https://code.google.com/archive/p/python-safethread">python-safethread</a>
project. Unfortunately, both of these earlier experiments exhibited a sharp
drop in single-thread
performance (at least 30% slower), due to the amount of fine-grained locking
necessary to compensate for the removal of the GIL. The Python 3.9 fork
is the first attempt at removing the GIL with an acceptable performance
impact.</p>
<p>The presence of the GIL in current Python releases
doesnt mean that you cant make good use of Python on multi-CPU machines!
You just have to be creative with dividing the work up between multiple
<em>processes</em> rather than multiple <em>threads</em>. The
<a class="reference internal" href="../library/concurrent.futures.html#concurrent.futures.ProcessPoolExecutor" title="concurrent.futures.ProcessPoolExecutor"><code class="xref py py-class docutils literal notranslate"><span class="pre">ProcessPoolExecutor</span></code></a> class in the new
<a class="reference internal" href="../library/concurrent.futures.html#module-concurrent.futures" title="concurrent.futures: Execute computations concurrently using threads or processes."><code class="xref py py-mod docutils literal notranslate"><span class="pre">concurrent.futures</span></code></a> module provides an easy way of doing so; the
<a class="reference internal" href="../library/multiprocessing.html#module-multiprocessing" title="multiprocessing: Process-based parallelism."><code class="xref py py-mod docutils literal notranslate"><span class="pre">multiprocessing</span></code></a> module provides a lower-level API in case you want
more control over dispatching of tasks.</p>
<p>Judicious use of C extensions will also help; if you use a C extension to
perform a time-consuming task, the extension can release the GIL while the
thread of execution is in the C code and allow other threads to get some work
done. Some standard library modules such as <a class="reference internal" href="../library/zlib.html#module-zlib" title="zlib: Low-level interface to compression and decompression routines compatible with gzip."><code class="xref py py-mod docutils literal notranslate"><span class="pre">zlib</span></code></a> and <a class="reference internal" href="../library/hashlib.html#module-hashlib" title="hashlib: Secure hash and message digest algorithms."><code class="xref py py-mod docutils literal notranslate"><span class="pre">hashlib</span></code></a>
already do this.</p>
<p>An alternative approach to reducing the impact of the GIL is
to make the GIL a per-interpreter-state lock rather than truly global.
This was <a class="reference internal" href="../whatsnew/3.12.html#whatsnew312-pep684"><span class="std std-ref">first implemented in Python 3.12</span></a> and is
available in the C API. A Python interface to it is expected in Python 3.13.
The main limitation to it at the moment is likely to be 3rd party extension
modules, since these must be written with multiple interpreters in mind in
order to be usable, so many older extension modules will not be usable.</p>
</section>
</section>
<section id="input-and-output">
<h2><a class="toc-backref" href="#id19" role="doc-backlink">Input and Output</a><a class="headerlink" href="#input-and-output" title="Link to this heading"></a></h2>
<section id="how-do-i-delete-a-file-and-other-file-questions">
<h3><a class="toc-backref" href="#id20" role="doc-backlink">How do I delete a file? (And other file questions…)</a><a class="headerlink" href="#how-do-i-delete-a-file-and-other-file-questions" title="Link to this heading"></a></h3>
<p>Use <code class="docutils literal notranslate"><span class="pre">os.remove(filename)</span></code> or <code class="docutils literal notranslate"><span class="pre">os.unlink(filename)</span></code>; for documentation, see
the <a class="reference internal" href="../library/os.html#module-os" title="os: Miscellaneous operating system interfaces."><code class="xref py py-mod docutils literal notranslate"><span class="pre">os</span></code></a> module. The two functions are identical; <a class="reference internal" href="../library/os.html#os.unlink" title="os.unlink"><code class="xref py py-func docutils literal notranslate"><span class="pre">unlink()</span></code></a> is simply
the name of the Unix system call for this function.</p>
<p>To remove a directory, use <a class="reference internal" href="../library/os.html#os.rmdir" title="os.rmdir"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.rmdir()</span></code></a>; use <a class="reference internal" href="../library/os.html#os.mkdir" title="os.mkdir"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.mkdir()</span></code></a> to create one.
<code class="docutils literal notranslate"><span class="pre">os.makedirs(path)</span></code> will create any intermediate directories in <code class="docutils literal notranslate"><span class="pre">path</span></code> that
dont exist. <code class="docutils literal notranslate"><span class="pre">os.removedirs(path)</span></code> will remove intermediate directories as
long as theyre empty; if you want to delete an entire directory tree and its
contents, use <a class="reference internal" href="../library/shutil.html#shutil.rmtree" title="shutil.rmtree"><code class="xref py py-func docutils literal notranslate"><span class="pre">shutil.rmtree()</span></code></a>.</p>
<p>To rename a file, use <code class="docutils literal notranslate"><span class="pre">os.rename(old_path,</span> <span class="pre">new_path)</span></code>.</p>
<p>To truncate a file, open it using <code class="docutils literal notranslate"><span class="pre">f</span> <span class="pre">=</span> <span class="pre">open(filename,</span> <span class="pre">&quot;rb+&quot;)</span></code>, and use
<code class="docutils literal notranslate"><span class="pre">f.truncate(offset)</span></code>; offset defaults to the current seek position. Theres
also <code class="docutils literal notranslate"><span class="pre">os.ftruncate(fd,</span> <span class="pre">offset)</span></code> for files opened with <a class="reference internal" href="../library/os.html#os.open" title="os.open"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.open()</span></code></a>, where
<em>fd</em> is the file descriptor (a small integer).</p>
<p>The <a class="reference internal" href="../library/shutil.html#module-shutil" title="shutil: High-level file operations, including copying."><code class="xref py py-mod docutils literal notranslate"><span class="pre">shutil</span></code></a> module also contains a number of functions to work on files
including <a class="reference internal" href="../library/shutil.html#shutil.copyfile" title="shutil.copyfile"><code class="xref py py-func docutils literal notranslate"><span class="pre">copyfile()</span></code></a>, <a class="reference internal" href="../library/shutil.html#shutil.copytree" title="shutil.copytree"><code class="xref py py-func docutils literal notranslate"><span class="pre">copytree()</span></code></a>, and
<a class="reference internal" href="../library/shutil.html#shutil.rmtree" title="shutil.rmtree"><code class="xref py py-func docutils literal notranslate"><span class="pre">rmtree()</span></code></a>.</p>
</section>
<section id="how-do-i-copy-a-file">
<h3><a class="toc-backref" href="#id21" role="doc-backlink">How do I copy a file?</a><a class="headerlink" href="#how-do-i-copy-a-file" title="Link to this heading"></a></h3>
<p>The <a class="reference internal" href="../library/shutil.html#module-shutil" title="shutil: High-level file operations, including copying."><code class="xref py py-mod docutils literal notranslate"><span class="pre">shutil</span></code></a> module contains a <a class="reference internal" href="../library/shutil.html#shutil.copyfile" title="shutil.copyfile"><code class="xref py py-func docutils literal notranslate"><span class="pre">copyfile()</span></code></a> function.
Note that on Windows NTFS volumes, it does not copy
<a class="reference external" href="https://en.wikipedia.org/wiki/NTFS#Alternate_data_stream_(ADS)">alternate data streams</a>
nor <a class="reference external" href="https://en.wikipedia.org/wiki/Resource_fork">resource forks</a>
on macOS HFS+ volumes, though both are now rarely used.
It also doesnt copy file permissions and metadata, though using
<a class="reference internal" href="../library/shutil.html#shutil.copy2" title="shutil.copy2"><code class="xref py py-func docutils literal notranslate"><span class="pre">shutil.copy2()</span></code></a> instead will preserve most (though not all) of it.</p>
</section>
<section id="how-do-i-read-or-write-binary-data">
<h3><a class="toc-backref" href="#id22" role="doc-backlink">How do I read (or write) binary data?</a><a class="headerlink" href="#how-do-i-read-or-write-binary-data" title="Link to this heading"></a></h3>
<p>To read or write complex binary data formats, its best to use the <a class="reference internal" href="../library/struct.html#module-struct" title="struct: Interpret bytes as packed binary data."><code class="xref py py-mod docutils literal notranslate"><span class="pre">struct</span></code></a>
module. It allows you to take a string containing binary data (usually numbers)
and convert it to Python objects; and vice versa.</p>
<p>For example, the following code reads two 2-byte integers and one 4-byte integer
in big-endian format from a file:</p>
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="kn">import</span><span class="w"> </span><span class="nn">struct</span>
<span class="k">with</span> <span class="nb">open</span><span class="p">(</span><span class="n">filename</span><span class="p">,</span> <span class="s2">&quot;rb&quot;</span><span class="p">)</span> <span class="k">as</span> <span class="n">f</span><span class="p">:</span>
<span class="n">s</span> <span class="o">=</span> <span class="n">f</span><span class="o">.</span><span class="n">read</span><span class="p">(</span><span class="mi">8</span><span class="p">)</span>
<span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">,</span> <span class="n">z</span> <span class="o">=</span> <span class="n">struct</span><span class="o">.</span><span class="n">unpack</span><span class="p">(</span><span class="s2">&quot;&gt;hhl&quot;</span><span class="p">,</span> <span class="n">s</span><span class="p">)</span>
</pre></div>
</div>
<p>The &gt; in the format string forces big-endian data; the letter h reads one
“short integer” (2 bytes), and l reads one “long integer” (4 bytes) from the
string.</p>
<p>For data that is more regular (e.g. a homogeneous list of ints or floats),
you can also use the <a class="reference internal" href="../library/array.html#module-array" title="array: Space efficient arrays of uniformly typed numeric values."><code class="xref py py-mod docutils literal notranslate"><span class="pre">array</span></code></a> module.</p>
<div class="admonition note">
<p class="admonition-title">Note</p>
<p>To read and write binary data, it is mandatory to open the file in
binary mode (here, passing <code class="docutils literal notranslate"><span class="pre">&quot;rb&quot;</span></code> to <a class="reference internal" href="../library/functions.html#open" title="open"><code class="xref py py-func docutils literal notranslate"><span class="pre">open()</span></code></a>). If you use
<code class="docutils literal notranslate"><span class="pre">&quot;r&quot;</span></code> instead (the default), the file will be open in text mode
and <code class="docutils literal notranslate"><span class="pre">f.read()</span></code> will return <a class="reference internal" href="../library/stdtypes.html#str" title="str"><code class="xref py py-class docutils literal notranslate"><span class="pre">str</span></code></a> objects rather than
<a class="reference internal" href="../library/stdtypes.html#bytes" title="bytes"><code class="xref py py-class docutils literal notranslate"><span class="pre">bytes</span></code></a> objects.</p>
</div>
</section>
<section id="i-can-t-seem-to-use-os-read-on-a-pipe-created-with-os-popen-why">
<h3><a class="toc-backref" href="#id23" role="doc-backlink">I cant seem to use os.read() on a pipe created with os.popen(); why?</a><a class="headerlink" href="#i-can-t-seem-to-use-os-read-on-a-pipe-created-with-os-popen-why" title="Link to this heading"></a></h3>
<p><a class="reference internal" href="../library/os.html#os.read" title="os.read"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.read()</span></code></a> is a low-level function which takes a file descriptor, a small
integer representing the opened file. <a class="reference internal" href="../library/os.html#os.popen" title="os.popen"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.popen()</span></code></a> creates a high-level
file object, the same type returned by the built-in <a class="reference internal" href="../library/functions.html#open" title="open"><code class="xref py py-func docutils literal notranslate"><span class="pre">open()</span></code></a> function.
Thus, to read <em>n</em> bytes from a pipe <em>p</em> created with <a class="reference internal" href="../library/os.html#os.popen" title="os.popen"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.popen()</span></code></a>, you need to
use <code class="docutils literal notranslate"><span class="pre">p.read(n)</span></code>.</p>
</section>
<section id="how-do-i-access-the-serial-rs232-port">
<h3><a class="toc-backref" href="#id24" role="doc-backlink">How do I access the serial (RS232) port?</a><a class="headerlink" href="#how-do-i-access-the-serial-rs232-port" title="Link to this heading"></a></h3>
<p>For Win32, OSX, Linux, BSD, Jython, IronPython:</p>
<blockquote>
<div><p><a class="extlink-pypi reference external" href="https://pypi.org/project/pyserial/">pyserial</a></p>
</div></blockquote>
<p>For Unix, see a Usenet post by Mitch Chapman:</p>
<blockquote>
<div><p><a class="reference external" href="https://groups.google.com/groups?selm=34A04430.CF9&#64;ohioee.com">https://groups.google.com/groups?selm=34A04430.CF9&#64;ohioee.com</a></p>
</div></blockquote>
</section>
<section id="why-doesn-t-closing-sys-stdout-stdin-stderr-really-close-it">
<h3><a class="toc-backref" href="#id25" role="doc-backlink">Why doesnt closing sys.stdout (stdin, stderr) really close it?</a><a class="headerlink" href="#why-doesn-t-closing-sys-stdout-stdin-stderr-really-close-it" title="Link to this heading"></a></h3>
<p>Python <a class="reference internal" href="../glossary.html#term-file-object"><span class="xref std std-term">file objects</span></a> are a high-level layer of
abstraction on low-level C file descriptors.</p>
<p>For most file objects you create in Python via the built-in <a class="reference internal" href="../library/functions.html#open" title="open"><code class="xref py py-func docutils literal notranslate"><span class="pre">open()</span></code></a>
function, <code class="docutils literal notranslate"><span class="pre">f.close()</span></code> marks the Python file object as being closed from
Pythons point of view, and also arranges to close the underlying C file
descriptor. This also happens automatically in <code class="docutils literal notranslate"><span class="pre">f</span></code>s destructor, when
<code class="docutils literal notranslate"><span class="pre">f</span></code> becomes garbage.</p>
<p>But stdin, stdout and stderr are treated specially by Python, because of the
special status also given to them by C. Running <code class="docutils literal notranslate"><span class="pre">sys.stdout.close()</span></code> marks
the Python-level file object as being closed, but does <em>not</em> close the
associated C file descriptor.</p>
<p>To close the underlying C file descriptor for one of these three, you should
first be sure thats what you really want to do (e.g., you may confuse
extension modules trying to do I/O). If it is, use <a class="reference internal" href="../library/os.html#os.close" title="os.close"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.close()</span></code></a>:</p>
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="n">os</span><span class="o">.</span><span class="n">close</span><span class="p">(</span><span class="n">stdin</span><span class="o">.</span><span class="n">fileno</span><span class="p">())</span>
<span class="n">os</span><span class="o">.</span><span class="n">close</span><span class="p">(</span><span class="n">stdout</span><span class="o">.</span><span class="n">fileno</span><span class="p">())</span>
<span class="n">os</span><span class="o">.</span><span class="n">close</span><span class="p">(</span><span class="n">stderr</span><span class="o">.</span><span class="n">fileno</span><span class="p">())</span>
</pre></div>
</div>
<p>Or you can use the numeric constants 0, 1 and 2, respectively.</p>
</section>
</section>
<section id="network-internet-programming">
<h2><a class="toc-backref" href="#id26" role="doc-backlink">Network/Internet Programming</a><a class="headerlink" href="#network-internet-programming" title="Link to this heading"></a></h2>
<section id="what-www-tools-are-there-for-python">
<h3><a class="toc-backref" href="#id27" role="doc-backlink">What WWW tools are there for Python?</a><a class="headerlink" href="#what-www-tools-are-there-for-python" title="Link to this heading"></a></h3>
<p>See the chapters titled <a class="reference internal" href="../library/internet.html#internet"><span class="std std-ref">Internet Protocols and Support</span></a> and <a class="reference internal" href="../library/netdata.html#netdata"><span class="std std-ref">Internet Data Handling</span></a> in the Library
Reference Manual. Python has many modules that will help you build server-side
and client-side web systems.</p>
<p>A summary of available frameworks is maintained by Paul Boddie at
<a class="reference external" href="https://wiki.python.org/moin/WebProgramming">https://wiki.python.org/moin/WebProgramming</a>.</p>
</section>
<section id="what-module-should-i-use-to-help-with-generating-html">
<h3><a class="toc-backref" href="#id28" role="doc-backlink">What module should I use to help with generating HTML?</a><a class="headerlink" href="#what-module-should-i-use-to-help-with-generating-html" title="Link to this heading"></a></h3>
<p>You can find a collection of useful links on the <a class="reference external" href="https://wiki.python.org/moin/WebProgramming">Web Programming wiki page</a>.</p>
</section>
<section id="how-do-i-send-mail-from-a-python-script">
<h3><a class="toc-backref" href="#id29" role="doc-backlink">How do I send mail from a Python script?</a><a class="headerlink" href="#how-do-i-send-mail-from-a-python-script" title="Link to this heading"></a></h3>
<p>Use the standard library module <a class="reference internal" href="../library/smtplib.html#module-smtplib" title="smtplib: SMTP protocol client (requires sockets)."><code class="xref py py-mod docutils literal notranslate"><span class="pre">smtplib</span></code></a>.</p>
<p>Heres a very simple interactive mail sender that uses it. This method will
work on any host that supports an SMTP listener.</p>
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="kn">import</span><span class="w"> </span><span class="nn">sys</span><span class="o">,</span><span class="w"> </span><span class="nn">smtplib</span>
<span class="n">fromaddr</span> <span class="o">=</span> <span class="nb">input</span><span class="p">(</span><span class="s2">&quot;From: &quot;</span><span class="p">)</span>
<span class="n">toaddrs</span> <span class="o">=</span> <span class="nb">input</span><span class="p">(</span><span class="s2">&quot;To: &quot;</span><span class="p">)</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s1">&#39;,&#39;</span><span class="p">)</span>
<span class="nb">print</span><span class="p">(</span><span class="s2">&quot;Enter message, end with ^D:&quot;</span><span class="p">)</span>
<span class="n">msg</span> <span class="o">=</span> <span class="s1">&#39;&#39;</span>
<span class="k">while</span> <span class="kc">True</span><span class="p">:</span>
<span class="n">line</span> <span class="o">=</span> <span class="n">sys</span><span class="o">.</span><span class="n">stdin</span><span class="o">.</span><span class="n">readline</span><span class="p">()</span>
<span class="k">if</span> <span class="ow">not</span> <span class="n">line</span><span class="p">:</span>
<span class="k">break</span>
<span class="n">msg</span> <span class="o">+=</span> <span class="n">line</span>
<span class="c1"># The actual mail send</span>
<span class="n">server</span> <span class="o">=</span> <span class="n">smtplib</span><span class="o">.</span><span class="n">SMTP</span><span class="p">(</span><span class="s1">&#39;localhost&#39;</span><span class="p">)</span>
<span class="n">server</span><span class="o">.</span><span class="n">sendmail</span><span class="p">(</span><span class="n">fromaddr</span><span class="p">,</span> <span class="n">toaddrs</span><span class="p">,</span> <span class="n">msg</span><span class="p">)</span>
<span class="n">server</span><span class="o">.</span><span class="n">quit</span><span class="p">()</span>
</pre></div>
</div>
<p>A Unix-only alternative uses sendmail. The location of the sendmail program
varies between systems; sometimes it is <code class="docutils literal notranslate"><span class="pre">/usr/lib/sendmail</span></code>, sometimes
<code class="docutils literal notranslate"><span class="pre">/usr/sbin/sendmail</span></code>. The sendmail manual page will help you out. Heres
some sample code:</p>
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="kn">import</span><span class="w"> </span><span class="nn">os</span>
<span class="n">SENDMAIL</span> <span class="o">=</span> <span class="s2">&quot;/usr/sbin/sendmail&quot;</span> <span class="c1"># sendmail location</span>
<span class="n">p</span> <span class="o">=</span> <span class="n">os</span><span class="o">.</span><span class="n">popen</span><span class="p">(</span><span class="s2">&quot;</span><span class="si">%s</span><span class="s2"> -t -i&quot;</span> <span class="o">%</span> <span class="n">SENDMAIL</span><span class="p">,</span> <span class="s2">&quot;w&quot;</span><span class="p">)</span>
<span class="n">p</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s2">&quot;To: receiver@example.com</span><span class="se">\n</span><span class="s2">&quot;</span><span class="p">)</span>
<span class="n">p</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s2">&quot;Subject: test</span><span class="se">\n</span><span class="s2">&quot;</span><span class="p">)</span>
<span class="n">p</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s2">&quot;</span><span class="se">\n</span><span class="s2">&quot;</span><span class="p">)</span> <span class="c1"># blank line separating headers from body</span>
<span class="n">p</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s2">&quot;Some text</span><span class="se">\n</span><span class="s2">&quot;</span><span class="p">)</span>
<span class="n">p</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s2">&quot;some more text</span><span class="se">\n</span><span class="s2">&quot;</span><span class="p">)</span>
<span class="n">sts</span> <span class="o">=</span> <span class="n">p</span><span class="o">.</span><span class="n">close</span><span class="p">()</span>
<span class="k">if</span> <span class="n">sts</span> <span class="o">!=</span> <span class="mi">0</span><span class="p">:</span>
<span class="nb">print</span><span class="p">(</span><span class="s2">&quot;Sendmail exit status&quot;</span><span class="p">,</span> <span class="n">sts</span><span class="p">)</span>
</pre></div>
</div>
</section>
<section id="how-do-i-avoid-blocking-in-the-connect-method-of-a-socket">
<h3><a class="toc-backref" href="#id30" role="doc-backlink">How do I avoid blocking in the connect() method of a socket?</a><a class="headerlink" href="#how-do-i-avoid-blocking-in-the-connect-method-of-a-socket" title="Link to this heading"></a></h3>
<p>The <a class="reference internal" href="../library/select.html#module-select" title="select: Wait for I/O completion on multiple streams."><code class="xref py py-mod docutils literal notranslate"><span class="pre">select</span></code></a> module is commonly used to help with asynchronous I/O on
sockets.</p>
<p>To prevent the TCP connect from blocking, you can set the socket to non-blocking
mode. Then when you do the <a class="reference internal" href="../library/socket.html#socket.socket.connect" title="socket.socket.connect"><code class="xref py py-meth docutils literal notranslate"><span class="pre">connect()</span></code></a>,
you will either connect immediately
(unlikely) or get an exception that contains the error number as <code class="docutils literal notranslate"><span class="pre">.errno</span></code>.
<code class="docutils literal notranslate"><span class="pre">errno.EINPROGRESS</span></code> indicates that the connection is in progress, but hasnt
finished yet. Different OSes will return different values, so youre going to
have to check whats returned on your system.</p>
<p>You can use the <a class="reference internal" href="../library/socket.html#socket.socket.connect_ex" title="socket.socket.connect_ex"><code class="xref py py-meth docutils literal notranslate"><span class="pre">connect_ex()</span></code></a> method
to avoid creating an exception.
It will just return the errno value.
To poll, you can call <a class="reference internal" href="../library/socket.html#socket.socket.connect_ex" title="socket.socket.connect_ex"><code class="xref py py-meth docutils literal notranslate"><span class="pre">connect_ex()</span></code></a> again later
<code class="docutils literal notranslate"><span class="pre">0</span></code> or <code class="docutils literal notranslate"><span class="pre">errno.EISCONN</span></code> indicate that youre connected or you can pass this
socket to <a class="reference internal" href="../library/select.html#select.select" title="select.select"><code class="xref py py-meth docutils literal notranslate"><span class="pre">select.select()</span></code></a> to check if its writable.</p>
<div class="admonition note">
<p class="admonition-title">Note</p>
<p>The <a class="reference internal" href="../library/asyncio.html#module-asyncio" title="asyncio: Asynchronous I/O."><code class="xref py py-mod docutils literal notranslate"><span class="pre">asyncio</span></code></a> module provides a general purpose single-threaded and
concurrent asynchronous library, which can be used for writing non-blocking
network code.
The third-party <a class="reference external" href="https://twisted.org/">Twisted</a> library is
a popular and feature-rich alternative.</p>
</div>
</section>
</section>
<section id="databases">
<h2><a class="toc-backref" href="#id31" role="doc-backlink">Databases</a><a class="headerlink" href="#databases" title="Link to this heading"></a></h2>
<section id="are-there-any-interfaces-to-database-packages-in-python">
<h3><a class="toc-backref" href="#id32" role="doc-backlink">Are there any interfaces to database packages in Python?</a><a class="headerlink" href="#are-there-any-interfaces-to-database-packages-in-python" title="Link to this heading"></a></h3>
<p>Yes.</p>
<p>Interfaces to disk-based hashes such as <a class="reference internal" href="../library/dbm.html#module-dbm.ndbm" title="dbm.ndbm: The New Database Manager (Unix)"><code class="xref py py-mod docutils literal notranslate"><span class="pre">DBM</span></code></a> and <a class="reference internal" href="../library/dbm.html#module-dbm.gnu" title="dbm.gnu: GNU database manager (Unix)"><code class="xref py py-mod docutils literal notranslate"><span class="pre">GDBM</span></code></a> are also included with standard Python. There is also the
<a class="reference internal" href="../library/sqlite3.html#module-sqlite3" title="sqlite3: A DB-API 2.0 implementation using SQLite 3.x."><code class="xref py py-mod docutils literal notranslate"><span class="pre">sqlite3</span></code></a> module, which provides a lightweight disk-based relational
database.</p>
<p>Support for most relational databases is available. See the
<a class="reference external" href="https://wiki.python.org/moin/DatabaseProgramming">DatabaseProgramming wiki page</a> for details.</p>
</section>
<section id="how-do-you-implement-persistent-objects-in-python">
<h3><a class="toc-backref" href="#id33" role="doc-backlink">How do you implement persistent objects in Python?</a><a class="headerlink" href="#how-do-you-implement-persistent-objects-in-python" title="Link to this heading"></a></h3>
<p>The <a class="reference internal" href="../library/pickle.html#module-pickle" title="pickle: Convert Python objects to streams of bytes and back."><code class="xref py py-mod docutils literal notranslate"><span class="pre">pickle</span></code></a> library module solves this in a very general way (though you
still cant store things like open files, sockets or windows), and the
<a class="reference internal" href="../library/shelve.html#module-shelve" title="shelve: Python object persistence."><code class="xref py py-mod docutils literal notranslate"><span class="pre">shelve</span></code></a> library module uses pickle and (g)dbm to create persistent
mappings containing arbitrary Python objects.</p>
</section>
</section>
<section id="mathematics-and-numerics">
<h2><a class="toc-backref" href="#id34" role="doc-backlink">Mathematics and Numerics</a><a class="headerlink" href="#mathematics-and-numerics" title="Link to this heading"></a></h2>
<section id="how-do-i-generate-random-numbers-in-python">
<h3><a class="toc-backref" href="#id35" role="doc-backlink">How do I generate random numbers in Python?</a><a class="headerlink" href="#how-do-i-generate-random-numbers-in-python" title="Link to this heading"></a></h3>
<p>The standard module <a class="reference internal" href="../library/random.html#module-random" title="random: Generate pseudo-random numbers with various common distributions."><code class="xref py py-mod docutils literal notranslate"><span class="pre">random</span></code></a> implements a random number generator. Usage
is simple:</p>
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="kn">import</span><span class="w"> </span><span class="nn">random</span>
<span class="n">random</span><span class="o">.</span><span class="n">random</span><span class="p">()</span>
</pre></div>
</div>
<p>This returns a random floating-point number in the range [0, 1).</p>
<p>There are also many other specialized generators in this module, such as:</p>
<ul class="simple">
<li><p><code class="docutils literal notranslate"><span class="pre">randrange(a,</span> <span class="pre">b)</span></code> chooses an integer in the range [a, b).</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">uniform(a,</span> <span class="pre">b)</span></code> chooses a floating-point number in the range [a, b).</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">normalvariate(mean,</span> <span class="pre">sdev)</span></code> samples the normal (Gaussian) distribution.</p></li>
</ul>
<p>Some higher-level functions operate on sequences directly, such as:</p>
<ul class="simple">
<li><p><code class="docutils literal notranslate"><span class="pre">choice(S)</span></code> chooses a random element from a given sequence.</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">shuffle(L)</span></code> shuffles a list in-place, i.e. permutes it randomly.</p></li>
</ul>
<p>Theres also a <code class="docutils literal notranslate"><span class="pre">Random</span></code> class you can instantiate to create independent
multiple random number generators.</p>
</section>
</section>
</section>
<div class="clearer"></div>
</div>
</div>
</div>
<div class="sphinxsidebar" role="navigation" aria-label="Main">
<div class="sphinxsidebarwrapper">
<div>
<h3><a href="../contents.html">Table of Contents</a></h3>
<ul>
<li><a class="reference internal" href="#">Library and Extension FAQ</a><ul>
<li><a class="reference internal" href="#general-library-questions">General Library Questions</a></li>
<li><a class="reference internal" href="#common-tasks">Common tasks</a></li>
<li><a class="reference internal" href="#threads">Threads</a></li>
<li><a class="reference internal" href="#input-and-output">Input and Output</a></li>
<li><a class="reference internal" href="#network-internet-programming">Network/Internet Programming</a></li>
<li><a class="reference internal" href="#databases">Databases</a></li>
<li><a class="reference internal" href="#mathematics-and-numerics">Mathematics and Numerics</a></li>
</ul>
</li>
</ul>
</div>
<div>
<h4>Previous topic</h4>
<p class="topless"><a href="design.html"
title="previous chapter">Design and History FAQ</a></p>
</div>
<div>
<h4>Next topic</h4>
<p class="topless"><a href="extending.html"
title="next chapter">Extending/Embedding FAQ</a></p>
</div>
<div role="note" aria-label="source link">
<h3>This Page</h3>
<ul class="this-page-menu">
<li><a href="../bugs.html">Report a Bug</a></li>
<li>
<a href="https://github.com/python/cpython/blob/main/Doc/faq/library.rst"
rel="nofollow">Show Source
</a>
</li>
</ul>
</div>
</div>
<div id="sidebarbutton" title="Collapse sidebar">
<span>«</span>
</div>
</div>
<div class="clearer"></div>
</div>
<div class="related" role="navigation" aria-label="Related">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="../genindex.html" title="General Index"
>index</a></li>
<li class="right" >
<a href="../py-modindex.html" title="Python Module Index"
>modules</a> |</li>
<li class="right" >
<a href="extending.html" title="Extending/Embedding FAQ"
>next</a> |</li>
<li class="right" >
<a href="design.html" title="Design and History FAQ"
>previous</a> |</li>
<li><img src="../_static/py.svg" alt="Python logo" style="vertical-align: middle; margin-top: -1px"/></li>
<li><a href="https://www.python.org/">Python</a> &#187;</li>
<li class="switchers">
<div class="language_switcher_placeholder"></div>
<div class="version_switcher_placeholder"></div>
</li>
<li>
</li>
<li id="cpython-language-and-version">
<a href="../index.html">3.13.3 Documentation</a> &#187;
</li>
<li class="nav-item nav-item-1"><a href="index.html" >Python Frequently Asked Questions</a> &#187;</li>
<li class="nav-item nav-item-this"><a href="">Library and Extension FAQ</a></li>
<li class="right">
<div class="inline-search" role="search">
<form class="inline-search" action="../search.html" method="get">
<input placeholder="Quick search" aria-label="Quick search" type="search" name="q" id="search-box" />
<input type="submit" value="Go" />
</form>
</div>
|
</li>
<li class="right">
<label class="theme-selector-label">
Theme
<select class="theme-selector" oninput="activateTheme(this.value)">
<option value="auto" selected>Auto</option>
<option value="light">Light</option>
<option value="dark">Dark</option>
</select>
</label> |</li>
</ul>
</div>
<div class="footer">
&copy;
<a href="../copyright.html">
Copyright
</a>
2001-2025, Python Software Foundation.
<br />
This page is licensed under the Python Software Foundation License Version 2.
<br />
Examples, recipes, and other code in the documentation are additionally licensed under the Zero Clause BSD License.
<br />
See <a href="/license.html">History and License</a> for more information.<br />
<br />
The Python Software Foundation is a non-profit corporation.
<a href="https://www.python.org/psf/donations/">Please donate.</a>
<br />
<br />
Last updated on Apr 08, 2025 (14:33 UTC).
<a href="/bugs.html">Found a bug</a>?
<br />
Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 8.2.3.
</div>
</body>
</html>

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,588 @@
<!DOCTYPE html>
<html lang="en" data-content_root="../">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="viewport" content="width=device-width, initial-scale=1" />
<meta property="og:title" content="Python on Windows FAQ" />
<meta property="og:type" content="website" />
<meta property="og:url" content="https://docs.python.org/3/faq/windows.html" />
<meta property="og:site_name" content="Python documentation" />
<meta property="og:description" content="Contents: Python on Windows FAQ- How do I run a Python program under Windows?, How do I make Python scripts executable?, Why does Python sometimes take so long to start?, How do I make an executabl..." />
<meta property="og:image" content="https://docs.python.org/3/_static/og-image.png" />
<meta property="og:image:alt" content="Python documentation" />
<meta name="description" content="Contents: Python on Windows FAQ- How do I run a Python program under Windows?, How do I make Python scripts executable?, Why does Python sometimes take so long to start?, How do I make an executabl..." />
<meta property="og:image:width" content="200">
<meta property="og:image:height" content="200">
<meta name="theme-color" content="#3776ab">
<title>Python on Windows FAQ &#8212; Python 3.13.3 documentation</title><meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" type="text/css" href="../_static/pygments.css?v=b86133f3" />
<link rel="stylesheet" type="text/css" href="../_static/pydoctheme.css?v=23252803" />
<link id="pygments_dark_css" media="(prefers-color-scheme: dark)" rel="stylesheet" type="text/css" href="../_static/pygments_dark.css?v=5349f25f" />
<script src="../_static/documentation_options.js?v=5d57ca2d"></script>
<script src="../_static/doctools.js?v=9bcbadda"></script>
<script src="../_static/sphinx_highlight.js?v=dc90522c"></script>
<script src="../_static/sidebar.js"></script>
<link rel="search" type="application/opensearchdescription+xml"
title="Search within Python 3.13.3 documentation"
href="../_static/opensearch.xml"/>
<link rel="author" title="About these documents" href="../about.html" />
<link rel="index" title="Index" href="../genindex.html" />
<link rel="search" title="Search" href="../search.html" />
<link rel="copyright" title="Copyright" href="../copyright.html" />
<link rel="next" title="Graphic User Interface FAQ" href="gui.html" />
<link rel="prev" title="Extending/Embedding FAQ" href="extending.html" />
<link rel="canonical" href="https://docs.python.org/3/faq/windows.html">
<style>
@media only screen {
table.full-width-table {
width: 100%;
}
}
</style>
<link rel="stylesheet" href="../_static/pydoctheme_dark.css" media="(prefers-color-scheme: dark)" id="pydoctheme_dark_css">
<link rel="shortcut icon" type="image/png" href="../_static/py.svg" />
<script type="text/javascript" src="../_static/copybutton.js"></script>
<script type="text/javascript" src="../_static/menu.js"></script>
<script type="text/javascript" src="../_static/search-focus.js"></script>
<script type="text/javascript" src="../_static/themetoggle.js"></script>
<script type="text/javascript" src="../_static/rtd_switcher.js"></script>
<meta name="readthedocs-addons-api-version" content="1">
</head>
<body>
<div class="mobile-nav">
<input type="checkbox" id="menuToggler" class="toggler__input" aria-controls="navigation"
aria-pressed="false" aria-expanded="false" role="button" aria-label="Menu" />
<nav class="nav-content" role="navigation">
<label for="menuToggler" class="toggler__label">
<span></span>
</label>
<span class="nav-items-wrapper">
<a href="https://www.python.org/" class="nav-logo">
<img src="../_static/py.svg" alt="Python logo"/>
</a>
<span class="version_switcher_placeholder"></span>
<form role="search" class="search" action="../search.html" method="get">
<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" class="search-icon">
<path fill-rule="nonzero" 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>
</svg>
<input placeholder="Quick search" aria-label="Quick search" type="search" name="q" />
<input type="submit" value="Go"/>
</form>
</span>
</nav>
<div class="menu-wrapper">
<nav class="menu" role="navigation" aria-label="main navigation">
<div class="language_switcher_placeholder"></div>
<label class="theme-selector-label">
Theme
<select class="theme-selector" oninput="activateTheme(this.value)">
<option value="auto" selected>Auto</option>
<option value="light">Light</option>
<option value="dark">Dark</option>
</select>
</label>
<div>
<h3><a href="../contents.html">Table of Contents</a></h3>
<ul>
<li><a class="reference internal" href="#">Python on Windows FAQ</a><ul>
<li><a class="reference internal" href="#how-do-i-run-a-python-program-under-windows">How do I run a Python program under Windows?</a></li>
<li><a class="reference internal" href="#how-do-i-make-python-scripts-executable">How do I make Python scripts executable?</a></li>
<li><a class="reference internal" href="#why-does-python-sometimes-take-so-long-to-start">Why does Python sometimes take so long to start?</a></li>
<li><a class="reference internal" href="#how-do-i-make-an-executable-from-a-python-script">How do I make an executable from a Python script?</a></li>
<li><a class="reference internal" href="#is-a-pyd-file-the-same-as-a-dll">Is a <code class="docutils literal notranslate"><span class="pre">*.pyd</span></code> file the same as a DLL?</a></li>
<li><a class="reference internal" href="#how-can-i-embed-python-into-a-windows-application">How can I embed Python into a Windows application?</a></li>
<li><a class="reference internal" href="#how-do-i-keep-editors-from-inserting-tabs-into-my-python-source">How do I keep editors from inserting tabs into my Python source?</a></li>
<li><a class="reference internal" href="#how-do-i-check-for-a-keypress-without-blocking">How do I check for a keypress without blocking?</a></li>
<li><a class="reference internal" href="#how-do-i-solve-the-missing-api-ms-win-crt-runtime-l1-1-0-dll-error">How do I solve the missing api-ms-win-crt-runtime-l1-1-0.dll error?</a></li>
</ul>
</li>
</ul>
</div>
<div>
<h4>Previous topic</h4>
<p class="topless"><a href="extending.html"
title="previous chapter">Extending/Embedding FAQ</a></p>
</div>
<div>
<h4>Next topic</h4>
<p class="topless"><a href="gui.html"
title="next chapter">Graphic User Interface FAQ</a></p>
</div>
<div role="note" aria-label="source link">
<h3>This Page</h3>
<ul class="this-page-menu">
<li><a href="../bugs.html">Report a Bug</a></li>
<li>
<a href="https://github.com/python/cpython/blob/main/Doc/faq/windows.rst"
rel="nofollow">Show Source
</a>
</li>
</ul>
</div>
</nav>
</div>
</div>
<div class="related" role="navigation" aria-label="Related">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="../genindex.html" title="General Index"
accesskey="I">index</a></li>
<li class="right" >
<a href="../py-modindex.html" title="Python Module Index"
>modules</a> |</li>
<li class="right" >
<a href="gui.html" title="Graphic User Interface FAQ"
accesskey="N">next</a> |</li>
<li class="right" >
<a href="extending.html" title="Extending/Embedding FAQ"
accesskey="P">previous</a> |</li>
<li><img src="../_static/py.svg" alt="Python logo" style="vertical-align: middle; margin-top: -1px"/></li>
<li><a href="https://www.python.org/">Python</a> &#187;</li>
<li class="switchers">
<div class="language_switcher_placeholder"></div>
<div class="version_switcher_placeholder"></div>
</li>
<li>
</li>
<li id="cpython-language-and-version">
<a href="../index.html">3.13.3 Documentation</a> &#187;
</li>
<li class="nav-item nav-item-1"><a href="index.html" accesskey="U">Python Frequently Asked Questions</a> &#187;</li>
<li class="nav-item nav-item-this"><a href="">Python on Windows FAQ</a></li>
<li class="right">
<div class="inline-search" role="search">
<form class="inline-search" action="../search.html" method="get">
<input placeholder="Quick search" aria-label="Quick search" type="search" name="q" id="search-box" />
<input type="submit" value="Go" />
</form>
</div>
|
</li>
<li class="right">
<label class="theme-selector-label">
Theme
<select class="theme-selector" oninput="activateTheme(this.value)">
<option value="auto" selected>Auto</option>
<option value="light">Light</option>
<option value="dark">Dark</option>
</select>
</label> |</li>
</ul>
</div>
<div class="document">
<div class="documentwrapper">
<div class="bodywrapper">
<div class="body" role="main">
<section id="python-on-windows-faq">
<span id="windows-faq"></span><h1><a class="toc-backref" href="#id1" role="doc-backlink">Python on Windows FAQ</a><a class="headerlink" href="#python-on-windows-faq" title="Link to this heading"></a></h1>
<nav class="contents" id="contents">
<p class="topic-title">Contents</p>
<ul class="simple">
<li><p><a class="reference internal" href="#python-on-windows-faq" id="id1">Python on Windows FAQ</a></p>
<ul>
<li><p><a class="reference internal" href="#how-do-i-run-a-python-program-under-windows" id="id2">How do I run a Python program under Windows?</a></p></li>
<li><p><a class="reference internal" href="#how-do-i-make-python-scripts-executable" id="id3">How do I make Python scripts executable?</a></p></li>
<li><p><a class="reference internal" href="#why-does-python-sometimes-take-so-long-to-start" id="id4">Why does Python sometimes take so long to start?</a></p></li>
<li><p><a class="reference internal" href="#how-do-i-make-an-executable-from-a-python-script" id="id5">How do I make an executable from a Python script?</a></p></li>
<li><p><a class="reference internal" href="#is-a-pyd-file-the-same-as-a-dll" id="id6">Is a <code class="docutils literal notranslate"><span class="pre">*.pyd</span></code> file the same as a DLL?</a></p></li>
<li><p><a class="reference internal" href="#how-can-i-embed-python-into-a-windows-application" id="id7">How can I embed Python into a Windows application?</a></p></li>
<li><p><a class="reference internal" href="#how-do-i-keep-editors-from-inserting-tabs-into-my-python-source" id="id8">How do I keep editors from inserting tabs into my Python source?</a></p></li>
<li><p><a class="reference internal" href="#how-do-i-check-for-a-keypress-without-blocking" id="id9">How do I check for a keypress without blocking?</a></p></li>
<li><p><a class="reference internal" href="#how-do-i-solve-the-missing-api-ms-win-crt-runtime-l1-1-0-dll-error" id="id10">How do I solve the missing api-ms-win-crt-runtime-l1-1-0.dll error?</a></p></li>
</ul>
</li>
</ul>
</nav>
<section id="how-do-i-run-a-python-program-under-windows">
<span id="faq-run-program-under-windows"></span><h2><a class="toc-backref" href="#id2" role="doc-backlink">How do I run a Python program under Windows?</a><a class="headerlink" href="#how-do-i-run-a-python-program-under-windows" title="Link to this heading"></a></h2>
<p>This is not necessarily a straightforward question. If you are already familiar
with running programs from the Windows command line then everything will seem
obvious; otherwise, you might need a little more guidance.</p>
<p>Unless you use some sort of integrated development environment, you will end up
<em>typing</em> Windows commands into what is referred to as a
“Command prompt window”. Usually you can create such a window from your
search bar by searching for <code class="docutils literal notranslate"><span class="pre">cmd</span></code>. You should be able to recognize
when you have started such a window because you will see a Windows “command
prompt”, which usually looks like this:</p>
<div class="highlight-doscon notranslate"><div class="highlight"><pre><span></span><span class="gp">C:\&gt;</span>
</pre></div>
</div>
<p>The letter may be different, and there might be other things after it, so you
might just as easily see something like:</p>
<div class="highlight-doscon notranslate"><div class="highlight"><pre><span></span><span class="gp">D:\YourName\Projects\Python&gt;</span>
</pre></div>
</div>
<p>depending on how your computer has been set up and what else you have recently
done with it. Once you have started such a window, you are well on the way to
running Python programs.</p>
<p>You need to realize that your Python scripts have to be processed by another
program called the Python <em>interpreter</em>. The interpreter reads your script,
compiles it into bytecodes, and then executes the bytecodes to run your
program. So, how do you arrange for the interpreter to handle your Python?</p>
<p>First, you need to make sure that your command window recognises the word
“py” as an instruction to start the interpreter. If you have opened a
command window, you should try entering the command <code class="docutils literal notranslate"><span class="pre">py</span></code> and hitting
return:</p>
<div class="highlight-doscon notranslate"><div class="highlight"><pre><span></span><span class="gp">C:\Users\YourName&gt;</span> py
</pre></div>
</div>
<p>You should then see something like:</p>
<div class="highlight-pycon notranslate"><div class="highlight"><pre><span></span><span class="go">Python 3.6.4 (v3.6.4:d48eceb, Dec 19 2017, 06:04:45) [MSC v.1900 32 bit (Intel)] on win32</span>
<span class="go">Type &quot;help&quot;, &quot;copyright&quot;, &quot;credits&quot; or &quot;license&quot; for more information.</span>
<span class="gp">&gt;&gt;&gt;</span>
</pre></div>
</div>
<p>You have started the interpreter in “interactive mode”. That means you can enter
Python statements or expressions interactively and have them executed or
evaluated while you wait. This is one of Pythons strongest features. Check it
by entering a few expressions of your choice and seeing the results:</p>
<div class="highlight-pycon notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="nb">print</span><span class="p">(</span><span class="s2">&quot;Hello&quot;</span><span class="p">)</span>
<span class="go">Hello</span>
<span class="gp">&gt;&gt;&gt; </span><span class="s2">&quot;Hello&quot;</span> <span class="o">*</span> <span class="mi">3</span>
<span class="go">&#39;HelloHelloHello&#39;</span>
</pre></div>
</div>
<p>Many people use the interactive mode as a convenient yet highly programmable
calculator. When you want to end your interactive Python session,
call the <a class="reference internal" href="../library/constants.html#exit" title="exit"><code class="xref py py-func docutils literal notranslate"><span class="pre">exit()</span></code></a> function or hold the <kbd class="kbd docutils literal notranslate">Ctrl</kbd> key down
while you enter a <kbd class="kbd docutils literal notranslate">Z</kbd>, then hit the “<kbd class="kbd docutils literal notranslate">Enter</kbd>” key to get
back to your Windows command prompt.</p>
<p>You may also find that you have a Start-menu entry such as <span class="menuselection">Start
‣ Programs ‣ Python 3.x ‣ Python (command line)</span> that results in you
seeing the <code class="docutils literal notranslate"><span class="pre">&gt;&gt;&gt;</span></code> prompt in a new window. If so, the window will disappear
after you call the <a class="reference internal" href="../library/constants.html#exit" title="exit"><code class="xref py py-func docutils literal notranslate"><span class="pre">exit()</span></code></a> function or enter the <kbd class="kbd docutils literal notranslate">Ctrl</kbd>-<kbd class="kbd docutils literal notranslate">Z</kbd>
character; Windows is running a single “python”
command in the window, and closes it when you terminate the interpreter.</p>
<p>Now that we know the <code class="docutils literal notranslate"><span class="pre">py</span></code> command is recognized, you can give your
Python script to it. Youll have to give either an absolute or a
relative path to the Python script. Lets say your Python script is
located in your desktop and is named <code class="docutils literal notranslate"><span class="pre">hello.py</span></code>, and your command
prompt is nicely opened in your home directory so youre seeing something
similar to:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>C:\Users\YourName&gt;
</pre></div>
</div>
<p>So now youll ask the <code class="docutils literal notranslate"><span class="pre">py</span></code> command to give your script to Python by
typing <code class="docutils literal notranslate"><span class="pre">py</span></code> followed by your script path:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>C:\Users\YourName&gt; py Desktop\hello.py
hello
</pre></div>
</div>
</section>
<section id="how-do-i-make-python-scripts-executable">
<h2><a class="toc-backref" href="#id3" role="doc-backlink">How do I make Python scripts executable?</a><a class="headerlink" href="#how-do-i-make-python-scripts-executable" title="Link to this heading"></a></h2>
<p>On Windows, the standard Python installer already associates the .py
extension with a file type (Python.File) and gives that file type an open
command that runs the interpreter (<code class="docutils literal notranslate"><span class="pre">D:\Program</span> <span class="pre">Files\Python\python.exe</span> <span class="pre">&quot;%1&quot;</span>
<span class="pre">%*</span></code>). This is enough to make scripts executable from the command prompt as
foo.py. If youd rather be able to execute the script by simple typing foo
with no extension you need to add .py to the PATHEXT environment variable.</p>
</section>
<section id="why-does-python-sometimes-take-so-long-to-start">
<h2><a class="toc-backref" href="#id4" role="doc-backlink">Why does Python sometimes take so long to start?</a><a class="headerlink" href="#why-does-python-sometimes-take-so-long-to-start" title="Link to this heading"></a></h2>
<p>Usually Python starts very quickly on Windows, but occasionally there are bug
reports that Python suddenly begins to take a long time to start up. This is
made even more puzzling because Python will work fine on other Windows systems
which appear to be configured identically.</p>
<p>The problem may be caused by a misconfiguration of virus checking software on
the problem machine. Some virus scanners have been known to introduce startup
overhead of two orders of magnitude when the scanner is configured to monitor
all reads from the filesystem. Try checking the configuration of virus scanning
software on your systems to ensure that they are indeed configured identically.
McAfee, when configured to scan all file system read activity, is a particular
offender.</p>
</section>
<section id="how-do-i-make-an-executable-from-a-python-script">
<h2><a class="toc-backref" href="#id5" role="doc-backlink">How do I make an executable from a Python script?</a><a class="headerlink" href="#how-do-i-make-an-executable-from-a-python-script" title="Link to this heading"></a></h2>
<p>See <a class="reference internal" href="programming.html#faq-create-standalone-binary"><span class="std std-ref">How can I create a stand-alone binary from a Python script?</span></a> for a list of tools that can be used to
make executables.</p>
</section>
<section id="is-a-pyd-file-the-same-as-a-dll">
<h2><a class="toc-backref" href="#id6" role="doc-backlink">Is a <code class="docutils literal notranslate"><span class="pre">*.pyd</span></code> file the same as a DLL?</a><a class="headerlink" href="#is-a-pyd-file-the-same-as-a-dll" title="Link to this heading"></a></h2>
<p>Yes, .pyd files are dlls, but there are a few differences. If you have a DLL
named <code class="docutils literal notranslate"><span class="pre">foo.pyd</span></code>, then it must have a function <code class="docutils literal notranslate"><span class="pre">PyInit_foo()</span></code>. You can then
write Python “import foo”, and Python will search for foo.pyd (as well as
foo.py, foo.pyc) and if it finds it, will attempt to call <code class="docutils literal notranslate"><span class="pre">PyInit_foo()</span></code> to
initialize it. You do not link your .exe with foo.lib, as that would cause
Windows to require the DLL to be present.</p>
<p>Note that the search path for foo.pyd is PYTHONPATH, not the same as the path
that Windows uses to search for foo.dll. Also, foo.pyd need not be present to
run your program, whereas if you linked your program with a dll, the dll is
required. Of course, foo.pyd is required if you want to say <code class="docutils literal notranslate"><span class="pre">import</span> <span class="pre">foo</span></code>. In
a DLL, linkage is declared in the source code with <code class="docutils literal notranslate"><span class="pre">__declspec(dllexport)</span></code>.
In a .pyd, linkage is defined in a list of available functions.</p>
</section>
<section id="how-can-i-embed-python-into-a-windows-application">
<h2><a class="toc-backref" href="#id7" role="doc-backlink">How can I embed Python into a Windows application?</a><a class="headerlink" href="#how-can-i-embed-python-into-a-windows-application" title="Link to this heading"></a></h2>
<p>Embedding the Python interpreter in a Windows app can be summarized as follows:</p>
<ol class="arabic">
<li><p>Do <strong>not</strong> build Python into your .exe file directly. On Windows, Python must
be a DLL to handle importing modules that are themselves DLLs. (This is the
first key undocumented fact.) Instead, link to <code class="file docutils literal notranslate"><span class="pre">python</span><em><span class="pre">NN</span></em><span class="pre">.dll</span></code>; it is
typically installed in <code class="docutils literal notranslate"><span class="pre">C:\Windows\System</span></code>. <em>NN</em> is the Python version, a
number such as “33” for Python 3.3.</p>
<p>You can link to Python in two different ways. Load-time linking means
linking against <code class="file docutils literal notranslate"><span class="pre">python</span><em><span class="pre">NN</span></em><span class="pre">.lib</span></code>, while run-time linking means linking
against <code class="file docutils literal notranslate"><span class="pre">python</span><em><span class="pre">NN</span></em><span class="pre">.dll</span></code>. (General note: <code class="file docutils literal notranslate"><span class="pre">python</span><em><span class="pre">NN</span></em><span class="pre">.lib</span></code> is the
so-called “import lib” corresponding to <code class="file docutils literal notranslate"><span class="pre">python</span><em><span class="pre">NN</span></em><span class="pre">.dll</span></code>. It merely
defines symbols for the linker.)</p>
<p>Run-time linking greatly simplifies link options; everything happens at run
time. Your code must load <code class="file docutils literal notranslate"><span class="pre">python</span><em><span class="pre">NN</span></em><span class="pre">.dll</span></code> using the Windows
<code class="docutils literal notranslate"><span class="pre">LoadLibraryEx()</span></code> routine. The code must also use access routines and data
in <code class="file docutils literal notranslate"><span class="pre">python</span><em><span class="pre">NN</span></em><span class="pre">.dll</span></code> (that is, Pythons C APIs) using pointers obtained
by the Windows <code class="docutils literal notranslate"><span class="pre">GetProcAddress()</span></code> routine. Macros can make using these
pointers transparent to any C code that calls routines in Pythons C API.</p>
</li>
<li><p>If you use SWIG, it is easy to create a Python “extension module” that will
make the apps data and methods available to Python. SWIG will handle just
about all the grungy details for you. The result is C code that you link
<em>into</em> your .exe file (!) You do <strong>not</strong> have to create a DLL file, and this
also simplifies linking.</p></li>
<li><p>SWIG will create an init function (a C function) whose name depends on the
name of the extension module. For example, if the name of the module is leo,
the init function will be called initleo(). If you use SWIG shadow classes,
as you should, the init function will be called initleoc(). This initializes
a mostly hidden helper class used by the shadow class.</p>
<p>The reason you can link the C code in step 2 into your .exe file is that
calling the initialization function is equivalent to importing the module
into Python! (This is the second key undocumented fact.)</p>
</li>
<li><p>In short, you can use the following code to initialize the Python interpreter
with your extension module.</p>
<div class="highlight-c notranslate"><div class="highlight"><pre><span></span><span class="cp">#include</span><span class="w"> </span><span class="cpf">&lt;Python.h&gt;</span>
<span class="p">...</span>
<span class="n">Py_Initialize</span><span class="p">();</span><span class="w"> </span><span class="c1">// Initialize Python.</span>
<span class="n">initmyAppc</span><span class="p">();</span><span class="w"> </span><span class="c1">// Initialize (import) the helper class.</span>
<span class="n">PyRun_SimpleString</span><span class="p">(</span><span class="s">&quot;import myApp&quot;</span><span class="p">);</span><span class="w"> </span><span class="c1">// Import the shadow class.</span>
</pre></div>
</div>
</li>
<li><p>There are two problems with Pythons C API which will become apparent if you
use a compiler other than MSVC, the compiler used to build pythonNN.dll.</p>
<p>Problem 1: The so-called “Very High Level” functions that take <code class="docutils literal notranslate"><span class="pre">FILE</span> <span class="pre">*</span></code>
arguments will not work in a multi-compiler environment because each
compilers notion of a <code class="docutils literal notranslate"><span class="pre">struct</span> <span class="pre">FILE</span></code> will be different. From an implementation
standpoint these are very low level functions.</p>
<p>Problem 2: SWIG generates the following code when generating wrappers to void
functions:</p>
<div class="highlight-c notranslate"><div class="highlight"><pre><span></span><span class="n">Py_INCREF</span><span class="p">(</span><span class="n">Py_None</span><span class="p">);</span>
<span class="n">_resultobj</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">Py_None</span><span class="p">;</span>
<span class="k">return</span><span class="w"> </span><span class="n">_resultobj</span><span class="p">;</span>
</pre></div>
</div>
<p>Alas, Py_None is a macro that expands to a reference to a complex data
structure called _Py_NoneStruct inside pythonNN.dll. Again, this code will
fail in a mult-compiler environment. Replace such code by:</p>
<div class="highlight-c notranslate"><div class="highlight"><pre><span></span><span class="k">return</span><span class="w"> </span><span class="n">Py_BuildValue</span><span class="p">(</span><span class="s">&quot;&quot;</span><span class="p">);</span>
</pre></div>
</div>
<p>It may be possible to use SWIGs <code class="docutils literal notranslate"><span class="pre">%typemap</span></code> command to make the change
automatically, though I have not been able to get this to work (Im a
complete SWIG newbie).</p>
</li>
<li><p>Using a Python shell script to put up a Python interpreter window from inside
your Windows app is not a good idea; the resulting window will be independent
of your apps windowing system. Rather, you (or the wxPythonWindow class)
should create a “native” interpreter window. It is easy to connect that
window to the Python interpreter. You can redirect Pythons i/o to _any_
object that supports read and write, so all you need is a Python object
(defined in your extension module) that contains read() and write() methods.</p></li>
</ol>
</section>
<section id="how-do-i-keep-editors-from-inserting-tabs-into-my-python-source">
<h2><a class="toc-backref" href="#id8" role="doc-backlink">How do I keep editors from inserting tabs into my Python source?</a><a class="headerlink" href="#how-do-i-keep-editors-from-inserting-tabs-into-my-python-source" title="Link to this heading"></a></h2>
<p>The FAQ does not recommend using tabs, and the Python style guide, <span class="target" id="index-0"></span><a class="pep reference external" href="https://peps.python.org/pep-0008/"><strong>PEP 8</strong></a>,
recommends 4 spaces for distributed Python code; this is also the Emacs
python-mode default.</p>
<p>Under any editor, mixing tabs and spaces is a bad idea. MSVC is no different in
this respect, and is easily configured to use spaces: Take <span class="menuselection">Tools
‣ Options ‣ Tabs</span>, and for file type “Default” set “Tab size” and “Indent
size” to 4, and select the “Insert spaces” radio button.</p>
<p>Python raises <a class="reference internal" href="../library/exceptions.html#IndentationError" title="IndentationError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">IndentationError</span></code></a> or <a class="reference internal" href="../library/exceptions.html#TabError" title="TabError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">TabError</span></code></a> if mixed tabs
and spaces are causing problems in leading whitespace.
You may also run the <a class="reference internal" href="../library/tabnanny.html#module-tabnanny" title="tabnanny: Tool for detecting white space related problems in Python source files in a directory tree."><code class="xref py py-mod docutils literal notranslate"><span class="pre">tabnanny</span></code></a> module to check a directory tree
in batch mode.</p>
</section>
<section id="how-do-i-check-for-a-keypress-without-blocking">
<h2><a class="toc-backref" href="#id9" role="doc-backlink">How do I check for a keypress without blocking?</a><a class="headerlink" href="#how-do-i-check-for-a-keypress-without-blocking" title="Link to this heading"></a></h2>
<p>Use the <a class="reference internal" href="../library/msvcrt.html#module-msvcrt" title="msvcrt: Miscellaneous useful routines from the MS VC++ runtime. (Windows)"><code class="xref py py-mod docutils literal notranslate"><span class="pre">msvcrt</span></code></a> module. This is a standard Windows-specific extension module.
It defines a function <code class="docutils literal notranslate"><span class="pre">kbhit()</span></code> which checks whether a keyboard hit is
present, and <code class="docutils literal notranslate"><span class="pre">getch()</span></code> which gets one character without echoing it.</p>
</section>
<section id="how-do-i-solve-the-missing-api-ms-win-crt-runtime-l1-1-0-dll-error">
<h2><a class="toc-backref" href="#id10" role="doc-backlink">How do I solve the missing api-ms-win-crt-runtime-l1-1-0.dll error?</a><a class="headerlink" href="#how-do-i-solve-the-missing-api-ms-win-crt-runtime-l1-1-0-dll-error" title="Link to this heading"></a></h2>
<p>This can occur on Python 3.5 and later when using Windows 8.1 or earlier without all updates having been installed.
First ensure your operating system is supported and is up to date, and if that does not resolve the issue,
visit the <a class="reference external" href="https://support.microsoft.com/en-us/help/3118401/">Microsoft support page</a>
for guidance on manually installing the C Runtime update.</p>
</section>
</section>
<div class="clearer"></div>
</div>
</div>
</div>
<div class="sphinxsidebar" role="navigation" aria-label="Main">
<div class="sphinxsidebarwrapper">
<div>
<h3><a href="../contents.html">Table of Contents</a></h3>
<ul>
<li><a class="reference internal" href="#">Python on Windows FAQ</a><ul>
<li><a class="reference internal" href="#how-do-i-run-a-python-program-under-windows">How do I run a Python program under Windows?</a></li>
<li><a class="reference internal" href="#how-do-i-make-python-scripts-executable">How do I make Python scripts executable?</a></li>
<li><a class="reference internal" href="#why-does-python-sometimes-take-so-long-to-start">Why does Python sometimes take so long to start?</a></li>
<li><a class="reference internal" href="#how-do-i-make-an-executable-from-a-python-script">How do I make an executable from a Python script?</a></li>
<li><a class="reference internal" href="#is-a-pyd-file-the-same-as-a-dll">Is a <code class="docutils literal notranslate"><span class="pre">*.pyd</span></code> file the same as a DLL?</a></li>
<li><a class="reference internal" href="#how-can-i-embed-python-into-a-windows-application">How can I embed Python into a Windows application?</a></li>
<li><a class="reference internal" href="#how-do-i-keep-editors-from-inserting-tabs-into-my-python-source">How do I keep editors from inserting tabs into my Python source?</a></li>
<li><a class="reference internal" href="#how-do-i-check-for-a-keypress-without-blocking">How do I check for a keypress without blocking?</a></li>
<li><a class="reference internal" href="#how-do-i-solve-the-missing-api-ms-win-crt-runtime-l1-1-0-dll-error">How do I solve the missing api-ms-win-crt-runtime-l1-1-0.dll error?</a></li>
</ul>
</li>
</ul>
</div>
<div>
<h4>Previous topic</h4>
<p class="topless"><a href="extending.html"
title="previous chapter">Extending/Embedding FAQ</a></p>
</div>
<div>
<h4>Next topic</h4>
<p class="topless"><a href="gui.html"
title="next chapter">Graphic User Interface FAQ</a></p>
</div>
<div role="note" aria-label="source link">
<h3>This Page</h3>
<ul class="this-page-menu">
<li><a href="../bugs.html">Report a Bug</a></li>
<li>
<a href="https://github.com/python/cpython/blob/main/Doc/faq/windows.rst"
rel="nofollow">Show Source
</a>
</li>
</ul>
</div>
</div>
<div id="sidebarbutton" title="Collapse sidebar">
<span>«</span>
</div>
</div>
<div class="clearer"></div>
</div>
<div class="related" role="navigation" aria-label="Related">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="../genindex.html" title="General Index"
>index</a></li>
<li class="right" >
<a href="../py-modindex.html" title="Python Module Index"
>modules</a> |</li>
<li class="right" >
<a href="gui.html" title="Graphic User Interface FAQ"
>next</a> |</li>
<li class="right" >
<a href="extending.html" title="Extending/Embedding FAQ"
>previous</a> |</li>
<li><img src="../_static/py.svg" alt="Python logo" style="vertical-align: middle; margin-top: -1px"/></li>
<li><a href="https://www.python.org/">Python</a> &#187;</li>
<li class="switchers">
<div class="language_switcher_placeholder"></div>
<div class="version_switcher_placeholder"></div>
</li>
<li>
</li>
<li id="cpython-language-and-version">
<a href="../index.html">3.13.3 Documentation</a> &#187;
</li>
<li class="nav-item nav-item-1"><a href="index.html" >Python Frequently Asked Questions</a> &#187;</li>
<li class="nav-item nav-item-this"><a href="">Python on Windows FAQ</a></li>
<li class="right">
<div class="inline-search" role="search">
<form class="inline-search" action="../search.html" method="get">
<input placeholder="Quick search" aria-label="Quick search" type="search" name="q" id="search-box" />
<input type="submit" value="Go" />
</form>
</div>
|
</li>
<li class="right">
<label class="theme-selector-label">
Theme
<select class="theme-selector" oninput="activateTheme(this.value)">
<option value="auto" selected>Auto</option>
<option value="light">Light</option>
<option value="dark">Dark</option>
</select>
</label> |</li>
</ul>
</div>
<div class="footer">
&copy;
<a href="../copyright.html">
Copyright
</a>
2001-2025, Python Software Foundation.
<br />
This page is licensed under the Python Software Foundation License Version 2.
<br />
Examples, recipes, and other code in the documentation are additionally licensed under the Zero Clause BSD License.
<br />
See <a href="/license.html">History and License</a> for more information.<br />
<br />
The Python Software Foundation is a non-profit corporation.
<a href="https://www.python.org/psf/donations/">Please donate.</a>
<br />
<br />
Last updated on Apr 08, 2025 (14:33 UTC).
<a href="/bugs.html">Found a bug</a>?
<br />
Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 8.2.3.
</div>
</body>
</html>