gooderp18绿色标准版
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

2579 lines
231KB

  1. <!DOCTYPE html>
  2. <html lang="en" data-content_root="../">
  3. <head>
  4. <meta charset="utf-8" />
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="viewport" content="width=device-width, initial-scale=1" />
  6. <meta property="og:title" content="sys — System-specific parameters and functions" />
  7. <meta property="og:type" content="website" />
  8. <meta property="og:url" content="https://docs.python.org/3/library/sys.html" />
  9. <meta property="og:site_name" content="Python documentation" />
  10. <meta property="og:description" content="This module provides access to some variables used or maintained by the interpreter and to functions that interact strongly with the interpreter. It is always available. Citations C99, ISO/IEC 9899..." />
  11. <meta property="og:image" content="https://docs.python.org/3/_static/og-image.png" />
  12. <meta property="og:image:alt" content="Python documentation" />
  13. <meta name="description" content="This module provides access to some variables used or maintained by the interpreter and to functions that interact strongly with the interpreter. It is always available. Citations C99, ISO/IEC 9899..." />
  14. <meta property="og:image:width" content="200" />
  15. <meta property="og:image:height" content="200" />
  16. <meta name="theme-color" content="#3776ab" />
  17. <title>sys — System-specific parameters and functions &#8212; Python 3.12.3 documentation</title><meta name="viewport" content="width=device-width, initial-scale=1.0">
  18. <link rel="stylesheet" type="text/css" href="../_static/pygments.css?v=80d5e7a1" />
  19. <link rel="stylesheet" type="text/css" href="../_static/pydoctheme.css?v=bb723527" />
  20. <link id="pygments_dark_css" media="(prefers-color-scheme: dark)" rel="stylesheet" type="text/css" href="../_static/pygments_dark.css?v=b20cc3f5" />
  21. <script src="../_static/documentation_options.js?v=2c828074"></script>
  22. <script src="../_static/doctools.js?v=888ff710"></script>
  23. <script src="../_static/sphinx_highlight.js?v=dc90522c"></script>
  24. <script src="../_static/sidebar.js"></script>
  25. <link rel="search" type="application/opensearchdescription+xml"
  26. title="Search within Python 3.12.3 documentation"
  27. href="../_static/opensearch.xml"/>
  28. <link rel="author" title="About these documents" href="../about.html" />
  29. <link rel="index" title="Index" href="../genindex.html" />
  30. <link rel="search" title="Search" href="../search.html" />
  31. <link rel="copyright" title="Copyright" href="../copyright.html" />
  32. <link rel="next" title="sys.monitoring — Execution event monitoring" href="sys.monitoring.html" />
  33. <link rel="prev" title="Python Runtime Services" href="python.html" />
  34. <link rel="canonical" href="https://docs.python.org/3/library/sys.html" />
  35. <style>
  36. @media only screen {
  37. table.full-width-table {
  38. width: 100%;
  39. }
  40. }
  41. </style>
  42. <link rel="stylesheet" href="../_static/pydoctheme_dark.css" media="(prefers-color-scheme: dark)" id="pydoctheme_dark_css">
  43. <link rel="shortcut icon" type="image/png" href="../_static/py.svg" />
  44. <script type="text/javascript" src="../_static/copybutton.js"></script>
  45. <script type="text/javascript" src="../_static/menu.js"></script>
  46. <script type="text/javascript" src="../_static/search-focus.js"></script>
  47. <script type="text/javascript" src="../_static/themetoggle.js"></script>
  48. </head>
  49. <body>
  50. <div class="mobile-nav">
  51. <input type="checkbox" id="menuToggler" class="toggler__input" aria-controls="navigation"
  52. aria-pressed="false" aria-expanded="false" role="button" aria-label="Menu" />
  53. <nav class="nav-content" role="navigation">
  54. <label for="menuToggler" class="toggler__label">
  55. <span></span>
  56. </label>
  57. <span class="nav-items-wrapper">
  58. <a href="https://www.python.org/" class="nav-logo">
  59. <img src="../_static/py.svg" alt="Python logo"/>
  60. </a>
  61. <span class="version_switcher_placeholder"></span>
  62. <form role="search" class="search" action="../search.html" method="get">
  63. <svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" class="search-icon">
  64. <path fill-rule="nonzero" fill="currentColor" d="M15.5 14h-.79l-.28-.27a6.5 6.5 0 001.48-5.34c-.47-2.78-2.79-5-5.59-5.34a6.505 6.505 0 00-7.27 7.27c.34 2.8 2.56 5.12 5.34 5.59a6.5 6.5 0 005.34-1.48l.27.28v.79l4.25 4.25c.41.41 1.08.41 1.49 0 .41-.41.41-1.08 0-1.49L15.5 14zm-6 0C7.01 14 5 11.99 5 9.5S7.01 5 9.5 5 14 7.01 14 9.5 11.99 14 9.5 14z"></path>
  65. </svg>
  66. <input placeholder="Quick search" aria-label="Quick search" type="search" name="q" />
  67. <input type="submit" value="Go"/>
  68. </form>
  69. </span>
  70. </nav>
  71. <div class="menu-wrapper">
  72. <nav class="menu" role="navigation" aria-label="main navigation">
  73. <div class="language_switcher_placeholder"></div>
  74. <label class="theme-selector-label">
  75. Theme
  76. <select class="theme-selector" oninput="activateTheme(this.value)">
  77. <option value="auto" selected>Auto</option>
  78. <option value="light">Light</option>
  79. <option value="dark">Dark</option>
  80. </select>
  81. </label>
  82. <div>
  83. <h4>Previous topic</h4>
  84. <p class="topless"><a href="python.html"
  85. title="previous chapter">Python Runtime Services</a></p>
  86. </div>
  87. <div>
  88. <h4>Next topic</h4>
  89. <p class="topless"><a href="sys.monitoring.html"
  90. title="next chapter"><code class="xref py py-mod docutils literal notranslate"><span class="pre">sys.monitoring</span></code> — Execution event monitoring</a></p>
  91. </div>
  92. <div role="note" aria-label="source link">
  93. <h3>This Page</h3>
  94. <ul class="this-page-menu">
  95. <li><a href="../bugs.html">Report a Bug</a></li>
  96. <li>
  97. <a href="https://github.com/python/cpython/blob/main/Doc/library/sys.rst"
  98. rel="nofollow">Show Source
  99. </a>
  100. </li>
  101. </ul>
  102. </div>
  103. </nav>
  104. </div>
  105. </div>
  106. <div class="related" role="navigation" aria-label="related navigation">
  107. <h3>Navigation</h3>
  108. <ul>
  109. <li class="right" style="margin-right: 10px">
  110. <a href="../genindex.html" title="General Index"
  111. accesskey="I">index</a></li>
  112. <li class="right" >
  113. <a href="../py-modindex.html" title="Python Module Index"
  114. >modules</a> |</li>
  115. <li class="right" >
  116. <a href="sys.monitoring.html" title="sys.monitoring — Execution event monitoring"
  117. accesskey="N">next</a> |</li>
  118. <li class="right" >
  119. <a href="python.html" title="Python Runtime Services"
  120. accesskey="P">previous</a> |</li>
  121. <li><img src="../_static/py.svg" alt="Python logo" style="vertical-align: middle; margin-top: -1px"/></li>
  122. <li><a href="https://www.python.org/">Python</a> &#187;</li>
  123. <li class="switchers">
  124. <div class="language_switcher_placeholder"></div>
  125. <div class="version_switcher_placeholder"></div>
  126. </li>
  127. <li>
  128. </li>
  129. <li id="cpython-language-and-version">
  130. <a href="../index.html">3.12.3 Documentation</a> &#187;
  131. </li>
  132. <li class="nav-item nav-item-1"><a href="index.html" >The Python Standard Library</a> &#187;</li>
  133. <li class="nav-item nav-item-2"><a href="python.html" accesskey="U">Python Runtime Services</a> &#187;</li>
  134. <li class="nav-item nav-item-this"><a href=""><code class="xref py py-mod docutils literal notranslate"><span class="pre">sys</span></code> — System-specific parameters and functions</a></li>
  135. <li class="right">
  136. <div class="inline-search" role="search">
  137. <form class="inline-search" action="../search.html" method="get">
  138. <input placeholder="Quick search" aria-label="Quick search" type="search" name="q" id="search-box" />
  139. <input type="submit" value="Go" />
  140. </form>
  141. </div>
  142. |
  143. </li>
  144. <li class="right">
  145. <label class="theme-selector-label">
  146. Theme
  147. <select class="theme-selector" oninput="activateTheme(this.value)">
  148. <option value="auto" selected>Auto</option>
  149. <option value="light">Light</option>
  150. <option value="dark">Dark</option>
  151. </select>
  152. </label> |</li>
  153. </ul>
  154. </div>
  155. <div class="document">
  156. <div class="documentwrapper">
  157. <div class="bodywrapper">
  158. <div class="body" role="main">
  159. <section id="module-sys">
  160. <span id="sys-system-specific-parameters-and-functions"></span><h1><a class="reference internal" href="#module-sys" title="sys: Access system-specific parameters and functions."><code class="xref py py-mod docutils literal notranslate"><span class="pre">sys</span></code></a> — System-specific parameters and functions<a class="headerlink" href="#module-sys" title="Link to this heading">¶</a></h1>
  161. <hr class="docutils" />
  162. <p>This module provides access to some variables used or maintained by the
  163. interpreter and to functions that interact strongly with the interpreter. It is
  164. always available.</p>
  165. <dl class="py data">
  166. <dt class="sig sig-object py" id="sys.abiflags">
  167. <span class="sig-prename descclassname"><span class="pre">sys.</span></span><span class="sig-name descname"><span class="pre">abiflags</span></span><a class="headerlink" href="#sys.abiflags" title="Link to this definition">¶</a></dt>
  168. <dd><p>On POSIX systems where Python was built with the standard <code class="docutils literal notranslate"><span class="pre">configure</span></code>
  169. script, this contains the ABI flags as specified by <span class="target" id="index-0"></span><a class="pep reference external" href="https://peps.python.org/pep-3149/"><strong>PEP 3149</strong></a>.</p>
  170. <div class="versionadded">
  171. <p><span class="versionmodified added">New in version 3.2.</span></p>
  172. </div>
  173. <div class="versionchanged">
  174. <p><span class="versionmodified changed">Changed in version 3.8: </span>Default flags became an empty string (<code class="docutils literal notranslate"><span class="pre">m</span></code> flag for pymalloc has been
  175. removed).</p>
  176. </div>
  177. <div class="availability docutils container">
  178. <p><a class="reference internal" href="intro.html#availability"><span class="std std-ref">Availability</span></a>: Unix.</p>
  179. </div>
  180. </dd></dl>
  181. <dl class="py function">
  182. <dt class="sig sig-object py" id="sys.addaudithook">
  183. <span class="sig-prename descclassname"><span class="pre">sys.</span></span><span class="sig-name descname"><span class="pre">addaudithook</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">hook</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#sys.addaudithook" title="Link to this definition">¶</a></dt>
  184. <dd><p>Append the callable <em>hook</em> to the list of active auditing hooks for the
  185. current (sub)interpreter.</p>
  186. <p>When an auditing event is raised through the <a class="reference internal" href="#sys.audit" title="sys.audit"><code class="xref py py-func docutils literal notranslate"><span class="pre">sys.audit()</span></code></a> function, each
  187. hook will be called in the order it was added with the event name and the
  188. tuple of arguments. Native hooks added by <a class="reference internal" href="../c-api/sys.html#c.PySys_AddAuditHook" title="PySys_AddAuditHook"><code class="xref c c-func docutils literal notranslate"><span class="pre">PySys_AddAuditHook()</span></code></a> are
  189. called first, followed by hooks added in the current (sub)interpreter. Hooks
  190. can then log the event, raise an exception to abort the operation,
  191. or terminate the process entirely.</p>
  192. <p>Note that audit hooks are primarily for collecting information about internal
  193. or otherwise unobservable actions, whether by Python or libraries written in
  194. Python. They are not suitable for implementing a “sandbox”. In particular,
  195. malicious code can trivially disable or bypass hooks added using this
  196. function. At a minimum, any security-sensitive hooks must be added using the
  197. C API <a class="reference internal" href="../c-api/sys.html#c.PySys_AddAuditHook" title="PySys_AddAuditHook"><code class="xref c c-func docutils literal notranslate"><span class="pre">PySys_AddAuditHook()</span></code></a> before initialising the runtime, and any
  198. modules allowing arbitrary memory modification (such as <a class="reference internal" href="ctypes.html#module-ctypes" title="ctypes: A foreign function library for Python."><code class="xref py py-mod docutils literal notranslate"><span class="pre">ctypes</span></code></a>) should
  199. be completely removed or closely monitored.</p>
  200. <p class="audit-hook"><p>Calling <a class="reference internal" href="#sys.addaudithook" title="sys.addaudithook"><code class="xref py py-func docutils literal notranslate"><span class="pre">sys.addaudithook()</span></code></a> will itself raise an auditing event
  201. named <code class="docutils literal notranslate"><span class="pre">sys.addaudithook</span></code> with no arguments. If any
  202. existing hooks raise an exception derived from <a class="reference internal" href="exceptions.html#RuntimeError" title="RuntimeError"><code class="xref py py-class docutils literal notranslate"><span class="pre">RuntimeError</span></code></a>, the
  203. new hook will not be added and the exception suppressed. As a result,
  204. callers cannot assume that their hook has been added unless they control
  205. all existing hooks.</p>
  206. </p>
  207. <p>See the <a class="reference internal" href="audit_events.html#audit-events"><span class="std std-ref">audit events table</span></a> for all events raised by
  208. CPython, and <span class="target" id="index-1"></span><a class="pep reference external" href="https://peps.python.org/pep-0578/"><strong>PEP 578</strong></a> for the original design discussion.</p>
  209. <div class="versionadded">
  210. <p><span class="versionmodified added">New in version 3.8.</span></p>
  211. </div>
  212. <div class="versionchanged">
  213. <p><span class="versionmodified changed">Changed in version 3.8.1: </span>Exceptions derived from <a class="reference internal" href="exceptions.html#Exception" title="Exception"><code class="xref py py-class docutils literal notranslate"><span class="pre">Exception</span></code></a> but not <a class="reference internal" href="exceptions.html#RuntimeError" title="RuntimeError"><code class="xref py py-class docutils literal notranslate"><span class="pre">RuntimeError</span></code></a>
  214. are no longer suppressed.</p>
  215. </div>
  216. <div class="impl-detail compound">
  217. <p><strong>CPython implementation detail:</strong> When tracing is enabled (see <a class="reference internal" href="#sys.settrace" title="sys.settrace"><code class="xref py py-func docutils literal notranslate"><span class="pre">settrace()</span></code></a>), Python hooks are only
  218. traced if the callable has a <code class="docutils literal notranslate"><span class="pre">__cantrace__</span></code> member that is set to a
  219. true value. Otherwise, trace functions will skip the hook.</p>
  220. </div>
  221. </dd></dl>
  222. <dl class="py data">
  223. <dt class="sig sig-object py" id="sys.argv">
  224. <span class="sig-prename descclassname"><span class="pre">sys.</span></span><span class="sig-name descname"><span class="pre">argv</span></span><a class="headerlink" href="#sys.argv" title="Link to this definition">¶</a></dt>
  225. <dd><p>The list of command line arguments passed to a Python script. <code class="docutils literal notranslate"><span class="pre">argv[0]</span></code> is the
  226. script name (it is operating system dependent whether this is a full pathname or
  227. not). If the command was executed using the <a class="reference internal" href="../using/cmdline.html#cmdoption-c"><code class="xref std std-option docutils literal notranslate"><span class="pre">-c</span></code></a> command line option to
  228. the interpreter, <code class="docutils literal notranslate"><span class="pre">argv[0]</span></code> is set to the string <code class="docutils literal notranslate"><span class="pre">'-c'</span></code>. If no script name
  229. was passed to the Python interpreter, <code class="docutils literal notranslate"><span class="pre">argv[0]</span></code> is the empty string.</p>
  230. <p>To loop over the standard input, or the list of files given on the
  231. command line, see the <a class="reference internal" href="fileinput.html#module-fileinput" title="fileinput: Loop over standard input or a list of files."><code class="xref py py-mod docutils literal notranslate"><span class="pre">fileinput</span></code></a> module.</p>
  232. <p>See also <a class="reference internal" href="#sys.orig_argv" title="sys.orig_argv"><code class="xref py py-data docutils literal notranslate"><span class="pre">sys.orig_argv</span></code></a>.</p>
  233. <div class="admonition note">
  234. <p class="admonition-title">Note</p>
  235. <p>On Unix, command line arguments are passed by bytes from OS. Python decodes
  236. them with filesystem encoding and “surrogateescape” error handler.
  237. When you need original bytes, you can get it by
  238. <code class="docutils literal notranslate"><span class="pre">[os.fsencode(arg)</span> <span class="pre">for</span> <span class="pre">arg</span> <span class="pre">in</span> <span class="pre">sys.argv]</span></code>.</p>
  239. </div>
  240. </dd></dl>
  241. <dl class="py function" id="auditing">
  242. <dt class="sig sig-object py" id="sys.audit">
  243. <span class="sig-prename descclassname"><span class="pre">sys.</span></span><span class="sig-name descname"><span class="pre">audit</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">event</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">*</span></span><span class="n"><span class="pre">args</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#sys.audit" title="Link to this definition">¶</a></dt>
  244. <dd><p id="index-2">Raise an auditing event and trigger any active auditing hooks.
  245. <em>event</em> is a string identifying the event, and <em>args</em> may contain
  246. optional arguments with more information about the event. The
  247. number and types of arguments for a given event are considered a
  248. public and stable API and should not be modified between releases.</p>
  249. <p>For example, one auditing event is named <code class="docutils literal notranslate"><span class="pre">os.chdir</span></code>. This event has
  250. one argument called <em>path</em> that will contain the requested new
  251. working directory.</p>
  252. <p><a class="reference internal" href="#sys.audit" title="sys.audit"><code class="xref py py-func docutils literal notranslate"><span class="pre">sys.audit()</span></code></a> will call the existing auditing hooks, passing
  253. the event name and arguments, and will re-raise the first exception
  254. from any hook. In general, if an exception is raised, it should not
  255. be handled and the process should be terminated as quickly as
  256. possible. This allows hook implementations to decide how to respond
  257. to particular events: they can merely log the event or abort the
  258. operation by raising an exception.</p>
  259. <p>Hooks are added using the <a class="reference internal" href="#sys.addaudithook" title="sys.addaudithook"><code class="xref py py-func docutils literal notranslate"><span class="pre">sys.addaudithook()</span></code></a> or
  260. <a class="reference internal" href="../c-api/sys.html#c.PySys_AddAuditHook" title="PySys_AddAuditHook"><code class="xref c c-func docutils literal notranslate"><span class="pre">PySys_AddAuditHook()</span></code></a> functions.</p>
  261. <p>The native equivalent of this function is <a class="reference internal" href="../c-api/sys.html#c.PySys_Audit" title="PySys_Audit"><code class="xref c c-func docutils literal notranslate"><span class="pre">PySys_Audit()</span></code></a>. Using the
  262. native function is preferred when possible.</p>
  263. <p>See the <a class="reference internal" href="audit_events.html#audit-events"><span class="std std-ref">audit events table</span></a> for all events raised by
  264. CPython.</p>
  265. <div class="versionadded">
  266. <p><span class="versionmodified added">New in version 3.8.</span></p>
  267. </div>
  268. </dd></dl>
  269. <dl class="py data">
  270. <dt class="sig sig-object py" id="sys.base_exec_prefix">
  271. <span class="sig-prename descclassname"><span class="pre">sys.</span></span><span class="sig-name descname"><span class="pre">base_exec_prefix</span></span><a class="headerlink" href="#sys.base_exec_prefix" title="Link to this definition">¶</a></dt>
  272. <dd><p>Set during Python startup, before <code class="docutils literal notranslate"><span class="pre">site.py</span></code> is run, to the same value as
  273. <a class="reference internal" href="#sys.exec_prefix" title="sys.exec_prefix"><code class="xref py py-data docutils literal notranslate"><span class="pre">exec_prefix</span></code></a>. If not running in a
  274. <a class="reference internal" href="venv.html#venv-def"><span class="std std-ref">virtual environment</span></a>, the values will stay the same; if
  275. <code class="docutils literal notranslate"><span class="pre">site.py</span></code> finds that a virtual environment is in use, the values of
  276. <a class="reference internal" href="#sys.prefix" title="sys.prefix"><code class="xref py py-data docutils literal notranslate"><span class="pre">prefix</span></code></a> and <a class="reference internal" href="#sys.exec_prefix" title="sys.exec_prefix"><code class="xref py py-data docutils literal notranslate"><span class="pre">exec_prefix</span></code></a> will be changed to point to the
  277. virtual environment, whereas <a class="reference internal" href="#sys.base_prefix" title="sys.base_prefix"><code class="xref py py-data docutils literal notranslate"><span class="pre">base_prefix</span></code></a> and
  278. <a class="reference internal" href="#sys.base_exec_prefix" title="sys.base_exec_prefix"><code class="xref py py-data docutils literal notranslate"><span class="pre">base_exec_prefix</span></code></a> will remain pointing to the base Python
  279. installation (the one which the virtual environment was created from).</p>
  280. <div class="versionadded">
  281. <p><span class="versionmodified added">New in version 3.3.</span></p>
  282. </div>
  283. </dd></dl>
  284. <dl class="py data">
  285. <dt class="sig sig-object py" id="sys.base_prefix">
  286. <span class="sig-prename descclassname"><span class="pre">sys.</span></span><span class="sig-name descname"><span class="pre">base_prefix</span></span><a class="headerlink" href="#sys.base_prefix" title="Link to this definition">¶</a></dt>
  287. <dd><p>Set during Python startup, before <code class="docutils literal notranslate"><span class="pre">site.py</span></code> is run, to the same value as
  288. <a class="reference internal" href="#sys.prefix" title="sys.prefix"><code class="xref py py-data docutils literal notranslate"><span class="pre">prefix</span></code></a>. If not running in a <a class="reference internal" href="venv.html#venv-def"><span class="std std-ref">virtual environment</span></a>, the values
  289. will stay the same; if <code class="docutils literal notranslate"><span class="pre">site.py</span></code> finds that a virtual environment is in
  290. use, the values of <a class="reference internal" href="#sys.prefix" title="sys.prefix"><code class="xref py py-data docutils literal notranslate"><span class="pre">prefix</span></code></a> and <a class="reference internal" href="#sys.exec_prefix" title="sys.exec_prefix"><code class="xref py py-data docutils literal notranslate"><span class="pre">exec_prefix</span></code></a> will be changed to
  291. point to the virtual environment, whereas <a class="reference internal" href="#sys.base_prefix" title="sys.base_prefix"><code class="xref py py-data docutils literal notranslate"><span class="pre">base_prefix</span></code></a> and
  292. <a class="reference internal" href="#sys.base_exec_prefix" title="sys.base_exec_prefix"><code class="xref py py-data docutils literal notranslate"><span class="pre">base_exec_prefix</span></code></a> will remain pointing to the base Python
  293. installation (the one which the virtual environment was created from).</p>
  294. <div class="versionadded">
  295. <p><span class="versionmodified added">New in version 3.3.</span></p>
  296. </div>
  297. </dd></dl>
  298. <dl class="py data">
  299. <dt class="sig sig-object py" id="sys.byteorder">
  300. <span class="sig-prename descclassname"><span class="pre">sys.</span></span><span class="sig-name descname"><span class="pre">byteorder</span></span><a class="headerlink" href="#sys.byteorder" title="Link to this definition">¶</a></dt>
  301. <dd><p>An indicator of the native byte order. This will have the value <code class="docutils literal notranslate"><span class="pre">'big'</span></code> on
  302. big-endian (most-significant byte first) platforms, and <code class="docutils literal notranslate"><span class="pre">'little'</span></code> on
  303. little-endian (least-significant byte first) platforms.</p>
  304. </dd></dl>
  305. <dl class="py data">
  306. <dt class="sig sig-object py" id="sys.builtin_module_names">
  307. <span class="sig-prename descclassname"><span class="pre">sys.</span></span><span class="sig-name descname"><span class="pre">builtin_module_names</span></span><a class="headerlink" href="#sys.builtin_module_names" title="Link to this definition">¶</a></dt>
  308. <dd><p>A tuple of strings containing the names of all modules that are compiled into this
  309. Python interpreter. (This information is not available in any other way —
  310. <code class="docutils literal notranslate"><span class="pre">modules.keys()</span></code> only lists the imported modules.)</p>
  311. <p>See also the <a class="reference internal" href="#sys.stdlib_module_names" title="sys.stdlib_module_names"><code class="xref py py-data docutils literal notranslate"><span class="pre">sys.stdlib_module_names</span></code></a> list.</p>
  312. </dd></dl>
  313. <dl class="py function">
  314. <dt class="sig sig-object py" id="sys.call_tracing">
  315. <span class="sig-prename descclassname"><span class="pre">sys.</span></span><span class="sig-name descname"><span class="pre">call_tracing</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">func</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">args</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#sys.call_tracing" title="Link to this definition">¶</a></dt>
  316. <dd><p>Call <code class="docutils literal notranslate"><span class="pre">func(*args)</span></code>, while tracing is enabled. The tracing state is saved,
  317. and restored afterwards. This is intended to be called from a debugger from
  318. a checkpoint, to recursively debug or profile some other code.</p>
  319. <p>Tracing is suspended while calling a tracing function set by
  320. <a class="reference internal" href="#sys.settrace" title="sys.settrace"><code class="xref py py-func docutils literal notranslate"><span class="pre">settrace()</span></code></a> or <a class="reference internal" href="#sys.setprofile" title="sys.setprofile"><code class="xref py py-func docutils literal notranslate"><span class="pre">setprofile()</span></code></a> to avoid infinite recursion.
  321. <code class="xref py py-func docutils literal notranslate"><span class="pre">call_tracing()</span></code> enables explicit recursion of the tracing function.</p>
  322. </dd></dl>
  323. <dl class="py data">
  324. <dt class="sig sig-object py" id="sys.copyright">
  325. <span class="sig-prename descclassname"><span class="pre">sys.</span></span><span class="sig-name descname"><span class="pre">copyright</span></span><a class="headerlink" href="#sys.copyright" title="Link to this definition">¶</a></dt>
  326. <dd><p>A string containing the copyright pertaining to the Python interpreter.</p>
  327. </dd></dl>
  328. <dl class="py function">
  329. <dt class="sig sig-object py" id="sys._clear_type_cache">
  330. <span class="sig-prename descclassname"><span class="pre">sys.</span></span><span class="sig-name descname"><span class="pre">_clear_type_cache</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#sys._clear_type_cache" title="Link to this definition">¶</a></dt>
  331. <dd><p>Clear the internal type cache. The type cache is used to speed up attribute
  332. and method lookups. Use the function <em>only</em> to drop unnecessary references
  333. during reference leak debugging.</p>
  334. <p>This function should be used for internal and specialized purposes only.</p>
  335. </dd></dl>
  336. <dl class="py function">
  337. <dt class="sig sig-object py" id="sys._current_frames">
  338. <span class="sig-prename descclassname"><span class="pre">sys.</span></span><span class="sig-name descname"><span class="pre">_current_frames</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#sys._current_frames" title="Link to this definition">¶</a></dt>
  339. <dd><p>Return a dictionary mapping each thread’s identifier to the topmost stack frame
  340. currently active in that thread at the time the function is called. Note that
  341. functions in the <a class="reference internal" href="traceback.html#module-traceback" title="traceback: Print or retrieve a stack traceback."><code class="xref py py-mod docutils literal notranslate"><span class="pre">traceback</span></code></a> module can build the call stack given such a
  342. frame.</p>
  343. <p>This is most useful for debugging deadlock: this function does not require the
  344. deadlocked threads’ cooperation, and such threads’ call stacks are frozen for as
  345. long as they remain deadlocked. The frame returned for a non-deadlocked thread
  346. may bear no relationship to that thread’s current activity by the time calling
  347. code examines the frame.</p>
  348. <p>This function should be used for internal and specialized purposes only.</p>
  349. <p class="audit-hook">Raises an <a class="reference internal" href="#auditing"><span class="std std-ref">auditing event</span></a> <code class="docutils literal notranslate"><span class="pre">sys._current_frames</span></code> with no arguments.</p>
  350. </dd></dl>
  351. <dl class="py function">
  352. <dt class="sig sig-object py" id="sys._current_exceptions">
  353. <span class="sig-prename descclassname"><span class="pre">sys.</span></span><span class="sig-name descname"><span class="pre">_current_exceptions</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#sys._current_exceptions" title="Link to this definition">¶</a></dt>
  354. <dd><p>Return a dictionary mapping each thread’s identifier to the topmost exception
  355. currently active in that thread at the time the function is called.
  356. If a thread is not currently handling an exception, it is not included in
  357. the result dictionary.</p>
  358. <p>This is most useful for statistical profiling.</p>
  359. <p>This function should be used for internal and specialized purposes only.</p>
  360. <p class="audit-hook">Raises an <a class="reference internal" href="#auditing"><span class="std std-ref">auditing event</span></a> <code class="docutils literal notranslate"><span class="pre">sys._current_exceptions</span></code> with no arguments.</p>
  361. <div class="versionchanged">
  362. <p><span class="versionmodified changed">Changed in version 3.12: </span>Each value in the dictionary is now a single exception instance, rather
  363. than a 3-tuple as returned from <code class="docutils literal notranslate"><span class="pre">sys.exc_info()</span></code>.</p>
  364. </div>
  365. </dd></dl>
  366. <dl class="py function">
  367. <dt class="sig sig-object py" id="sys.breakpointhook">
  368. <span class="sig-prename descclassname"><span class="pre">sys.</span></span><span class="sig-name descname"><span class="pre">breakpointhook</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#sys.breakpointhook" title="Link to this definition">¶</a></dt>
  369. <dd><p>This hook function is called by built-in <a class="reference internal" href="functions.html#breakpoint" title="breakpoint"><code class="xref py py-func docutils literal notranslate"><span class="pre">breakpoint()</span></code></a>. By default,
  370. it drops you into the <a class="reference internal" href="pdb.html#module-pdb" title="pdb: The Python debugger for interactive interpreters."><code class="xref py py-mod docutils literal notranslate"><span class="pre">pdb</span></code></a> debugger, but it can be set to any other
  371. function so that you can choose which debugger gets used.</p>
  372. <p>The signature of this function is dependent on what it calls. For example,
  373. the default binding (e.g. <code class="docutils literal notranslate"><span class="pre">pdb.set_trace()</span></code>) expects no arguments, but
  374. you might bind it to a function that expects additional arguments
  375. (positional and/or keyword). The built-in <code class="docutils literal notranslate"><span class="pre">breakpoint()</span></code> function passes
  376. its <code class="docutils literal notranslate"><span class="pre">*args</span></code> and <code class="docutils literal notranslate"><span class="pre">**kws</span></code> straight through. Whatever
  377. <code class="docutils literal notranslate"><span class="pre">breakpointhooks()</span></code> returns is returned from <code class="docutils literal notranslate"><span class="pre">breakpoint()</span></code>.</p>
  378. <p>The default implementation first consults the environment variable
  379. <span class="target" id="index-3"></span><a class="reference internal" href="../using/cmdline.html#envvar-PYTHONBREAKPOINT"><code class="xref std std-envvar docutils literal notranslate"><span class="pre">PYTHONBREAKPOINT</span></code></a>. If that is set to <code class="docutils literal notranslate"><span class="pre">&quot;0&quot;</span></code> then this function
  380. returns immediately; i.e. it is a no-op. If the environment variable is
  381. not set, or is set to the empty string, <code class="docutils literal notranslate"><span class="pre">pdb.set_trace()</span></code> is called.
  382. Otherwise this variable should name a function to run, using Python’s
  383. dotted-import nomenclature, e.g. <code class="docutils literal notranslate"><span class="pre">package.subpackage.module.function</span></code>.
  384. In this case, <code class="docutils literal notranslate"><span class="pre">package.subpackage.module</span></code> would be imported and the
  385. resulting module must have a callable named <code class="docutils literal notranslate"><span class="pre">function()</span></code>. This is run,
  386. passing in <code class="docutils literal notranslate"><span class="pre">*args</span></code> and <code class="docutils literal notranslate"><span class="pre">**kws</span></code>, and whatever <code class="docutils literal notranslate"><span class="pre">function()</span></code> returns,
  387. <code class="docutils literal notranslate"><span class="pre">sys.breakpointhook()</span></code> returns to the built-in <a class="reference internal" href="functions.html#breakpoint" title="breakpoint"><code class="xref py py-func docutils literal notranslate"><span class="pre">breakpoint()</span></code></a>
  388. function.</p>
  389. <p>Note that if anything goes wrong while importing the callable named by
  390. <span class="target" id="index-4"></span><a class="reference internal" href="../using/cmdline.html#envvar-PYTHONBREAKPOINT"><code class="xref std std-envvar docutils literal notranslate"><span class="pre">PYTHONBREAKPOINT</span></code></a>, a <a class="reference internal" href="exceptions.html#RuntimeWarning" title="RuntimeWarning"><code class="xref py py-exc docutils literal notranslate"><span class="pre">RuntimeWarning</span></code></a> is reported and the
  391. breakpoint is ignored.</p>
  392. <p>Also note that if <code class="docutils literal notranslate"><span class="pre">sys.breakpointhook()</span></code> is overridden programmatically,
  393. <span class="target" id="index-5"></span><a class="reference internal" href="../using/cmdline.html#envvar-PYTHONBREAKPOINT"><code class="xref std std-envvar docutils literal notranslate"><span class="pre">PYTHONBREAKPOINT</span></code></a> is <em>not</em> consulted.</p>
  394. <div class="versionadded">
  395. <p><span class="versionmodified added">New in version 3.7.</span></p>
  396. </div>
  397. </dd></dl>
  398. <dl class="py function">
  399. <dt class="sig sig-object py" id="sys._debugmallocstats">
  400. <span class="sig-prename descclassname"><span class="pre">sys.</span></span><span class="sig-name descname"><span class="pre">_debugmallocstats</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#sys._debugmallocstats" title="Link to this definition">¶</a></dt>
  401. <dd><p>Print low-level information to stderr about the state of CPython’s memory
  402. allocator.</p>
  403. <p>If Python is <a class="reference internal" href="../using/configure.html#debug-build"><span class="std std-ref">built in debug mode</span></a> (<a class="reference internal" href="../using/configure.html#cmdoption-with-pydebug"><code class="xref std std-option docutils literal notranslate"><span class="pre">configure</span>
  404. <span class="pre">--with-pydebug</span> <span class="pre">option</span></code></a>), it also performs some expensive
  405. internal consistency checks.</p>
  406. <div class="versionadded">
  407. <p><span class="versionmodified added">New in version 3.3.</span></p>
  408. </div>
  409. <div class="impl-detail compound">
  410. <p><strong>CPython implementation detail:</strong> This function is specific to CPython. The exact output format is not
  411. defined here, and may change.</p>
  412. </div>
  413. </dd></dl>
  414. <dl class="py data">
  415. <dt class="sig sig-object py" id="sys.dllhandle">
  416. <span class="sig-prename descclassname"><span class="pre">sys.</span></span><span class="sig-name descname"><span class="pre">dllhandle</span></span><a class="headerlink" href="#sys.dllhandle" title="Link to this definition">¶</a></dt>
  417. <dd><p>Integer specifying the handle of the Python DLL.</p>
  418. <div class="availability docutils container">
  419. <p><a class="reference internal" href="intro.html#availability"><span class="std std-ref">Availability</span></a>: Windows.</p>
  420. </div>
  421. </dd></dl>
  422. <dl class="py function">
  423. <dt class="sig sig-object py" id="sys.displayhook">
  424. <span class="sig-prename descclassname"><span class="pre">sys.</span></span><span class="sig-name descname"><span class="pre">displayhook</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">value</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#sys.displayhook" title="Link to this definition">¶</a></dt>
  425. <dd><p>If <em>value</em> is not <code class="docutils literal notranslate"><span class="pre">None</span></code>, this function prints <code class="docutils literal notranslate"><span class="pre">repr(value)</span></code> to
  426. <code class="docutils literal notranslate"><span class="pre">sys.stdout</span></code>, and saves <em>value</em> in <code class="docutils literal notranslate"><span class="pre">builtins._</span></code>. If <code class="docutils literal notranslate"><span class="pre">repr(value)</span></code> is
  427. not encodable to <code class="docutils literal notranslate"><span class="pre">sys.stdout.encoding</span></code> with <code class="docutils literal notranslate"><span class="pre">sys.stdout.errors</span></code> error
  428. handler (which is probably <code class="docutils literal notranslate"><span class="pre">'strict'</span></code>), encode it to
  429. <code class="docutils literal notranslate"><span class="pre">sys.stdout.encoding</span></code> with <code class="docutils literal notranslate"><span class="pre">'backslashreplace'</span></code> error handler.</p>
  430. <p><code class="docutils literal notranslate"><span class="pre">sys.displayhook</span></code> is called on the result of evaluating an <a class="reference internal" href="../glossary.html#term-expression"><span class="xref std std-term">expression</span></a>
  431. entered in an interactive Python session. The display of these values can be
  432. customized by assigning another one-argument function to <code class="docutils literal notranslate"><span class="pre">sys.displayhook</span></code>.</p>
  433. <p>Pseudo-code:</p>
  434. <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="k">def</span> <span class="nf">displayhook</span><span class="p">(</span><span class="n">value</span><span class="p">):</span>
  435. <span class="k">if</span> <span class="n">value</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
  436. <span class="k">return</span>
  437. <span class="c1"># Set &#39;_&#39; to None to avoid recursion</span>
  438. <span class="n">builtins</span><span class="o">.</span><span class="n">_</span> <span class="o">=</span> <span class="kc">None</span>
  439. <span class="n">text</span> <span class="o">=</span> <span class="nb">repr</span><span class="p">(</span><span class="n">value</span><span class="p">)</span>
  440. <span class="k">try</span><span class="p">:</span>
  441. <span class="n">sys</span><span class="o">.</span><span class="n">stdout</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="n">text</span><span class="p">)</span>
  442. <span class="k">except</span> <span class="ne">UnicodeEncodeError</span><span class="p">:</span>
  443. <span class="nb">bytes</span> <span class="o">=</span> <span class="n">text</span><span class="o">.</span><span class="n">encode</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">encoding</span><span class="p">,</span> <span class="s1">&#39;backslashreplace&#39;</span><span class="p">)</span>
  444. <span class="k">if</span> <span class="nb">hasattr</span><span class="p">(</span><span class="n">sys</span><span class="o">.</span><span class="n">stdout</span><span class="p">,</span> <span class="s1">&#39;buffer&#39;</span><span class="p">):</span>
  445. <span class="n">sys</span><span class="o">.</span><span class="n">stdout</span><span class="o">.</span><span class="n">buffer</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="nb">bytes</span><span class="p">)</span>
  446. <span class="k">else</span><span class="p">:</span>
  447. <span class="n">text</span> <span class="o">=</span> <span class="nb">bytes</span><span class="o">.</span><span class="n">decode</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">encoding</span><span class="p">,</span> <span class="s1">&#39;strict&#39;</span><span class="p">)</span>
  448. <span class="n">sys</span><span class="o">.</span><span class="n">stdout</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="n">text</span><span class="p">)</span>
  449. <span class="n">sys</span><span class="o">.</span><span class="n">stdout</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>
  450. <span class="n">builtins</span><span class="o">.</span><span class="n">_</span> <span class="o">=</span> <span class="n">value</span>
  451. </pre></div>
  452. </div>
  453. <div class="versionchanged">
  454. <p><span class="versionmodified changed">Changed in version 3.2: </span>Use <code class="docutils literal notranslate"><span class="pre">'backslashreplace'</span></code> error handler on <a class="reference internal" href="exceptions.html#UnicodeEncodeError" title="UnicodeEncodeError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">UnicodeEncodeError</span></code></a>.</p>
  455. </div>
  456. </dd></dl>
  457. <dl class="py data">
  458. <dt class="sig sig-object py" id="sys.dont_write_bytecode">
  459. <span class="sig-prename descclassname"><span class="pre">sys.</span></span><span class="sig-name descname"><span class="pre">dont_write_bytecode</span></span><a class="headerlink" href="#sys.dont_write_bytecode" title="Link to this definition">¶</a></dt>
  460. <dd><p>If this is true, Python won’t try to write <code class="docutils literal notranslate"><span class="pre">.pyc</span></code> files on the
  461. import of source modules. This value is initially set to <code class="docutils literal notranslate"><span class="pre">True</span></code> or
  462. <code class="docutils literal notranslate"><span class="pre">False</span></code> depending on the <a class="reference internal" href="../using/cmdline.html#cmdoption-B"><code class="xref std std-option docutils literal notranslate"><span class="pre">-B</span></code></a> command line option and the
  463. <span class="target" id="index-6"></span><a class="reference internal" href="../using/cmdline.html#envvar-PYTHONDONTWRITEBYTECODE"><code class="xref std std-envvar docutils literal notranslate"><span class="pre">PYTHONDONTWRITEBYTECODE</span></code></a> environment variable, but you can set it
  464. yourself to control bytecode file generation.</p>
  465. </dd></dl>
  466. <dl class="py data">
  467. <dt class="sig sig-object py" id="sys._emscripten_info">
  468. <span class="sig-prename descclassname"><span class="pre">sys.</span></span><span class="sig-name descname"><span class="pre">_emscripten_info</span></span><a class="headerlink" href="#sys._emscripten_info" title="Link to this definition">¶</a></dt>
  469. <dd><p>A <a class="reference internal" href="../glossary.html#term-named-tuple"><span class="xref std std-term">named tuple</span></a> holding information about the environment on the
  470. <em>wasm32-emscripten</em> platform. The named tuple is provisional and may change
  471. in the future.</p>
  472. <dl class="py attribute">
  473. <dt class="sig sig-object py" id="sys._emscripten_info.emscripten_version">
  474. <span class="sig-prename descclassname"><span class="pre">_emscripten_info.</span></span><span class="sig-name descname"><span class="pre">emscripten_version</span></span><a class="headerlink" href="#sys._emscripten_info.emscripten_version" title="Link to this definition">¶</a></dt>
  475. <dd><p>Emscripten version as tuple of ints (major, minor, micro), e.g. <code class="docutils literal notranslate"><span class="pre">(3,</span> <span class="pre">1,</span> <span class="pre">8)</span></code>.</p>
  476. </dd></dl>
  477. <dl class="py attribute">
  478. <dt class="sig sig-object py" id="sys._emscripten_info.runtime">
  479. <span class="sig-prename descclassname"><span class="pre">_emscripten_info.</span></span><span class="sig-name descname"><span class="pre">runtime</span></span><a class="headerlink" href="#sys._emscripten_info.runtime" title="Link to this definition">¶</a></dt>
  480. <dd><p>Runtime string, e.g. browser user agent, <code class="docutils literal notranslate"><span class="pre">'Node.js</span> <span class="pre">v14.18.2'</span></code>, or <code class="docutils literal notranslate"><span class="pre">'UNKNOWN'</span></code>.</p>
  481. </dd></dl>
  482. <dl class="py attribute">
  483. <dt class="sig sig-object py" id="sys._emscripten_info.pthreads">
  484. <span class="sig-prename descclassname"><span class="pre">_emscripten_info.</span></span><span class="sig-name descname"><span class="pre">pthreads</span></span><a class="headerlink" href="#sys._emscripten_info.pthreads" title="Link to this definition">¶</a></dt>
  485. <dd><p><code class="docutils literal notranslate"><span class="pre">True</span></code> if Python is compiled with Emscripten pthreads support.</p>
  486. </dd></dl>
  487. <dl class="py attribute">
  488. <dt class="sig sig-object py" id="sys._emscripten_info.shared_memory">
  489. <span class="sig-prename descclassname"><span class="pre">_emscripten_info.</span></span><span class="sig-name descname"><span class="pre">shared_memory</span></span><a class="headerlink" href="#sys._emscripten_info.shared_memory" title="Link to this definition">¶</a></dt>
  490. <dd><p><code class="docutils literal notranslate"><span class="pre">True</span></code> if Python is compiled with shared memory support.</p>
  491. </dd></dl>
  492. <div class="availability docutils container">
  493. <p><a class="reference internal" href="intro.html#availability"><span class="std std-ref">Availability</span></a>: Emscripten.</p>
  494. </div>
  495. <div class="versionadded">
  496. <p><span class="versionmodified added">New in version 3.11.</span></p>
  497. </div>
  498. </dd></dl>
  499. <dl class="py data">
  500. <dt class="sig sig-object py" id="sys.pycache_prefix">
  501. <span class="sig-prename descclassname"><span class="pre">sys.</span></span><span class="sig-name descname"><span class="pre">pycache_prefix</span></span><a class="headerlink" href="#sys.pycache_prefix" title="Link to this definition">¶</a></dt>
  502. <dd><p>If this is set (not <code class="docutils literal notranslate"><span class="pre">None</span></code>), Python will write bytecode-cache <code class="docutils literal notranslate"><span class="pre">.pyc</span></code>
  503. files to (and read them from) a parallel directory tree rooted at this
  504. directory, rather than from <code class="docutils literal notranslate"><span class="pre">__pycache__</span></code> directories in the source code
  505. tree. Any <code class="docutils literal notranslate"><span class="pre">__pycache__</span></code> directories in the source code tree will be ignored
  506. and new <code class="docutils literal notranslate"><span class="pre">.pyc</span></code> files written within the pycache prefix. Thus if you use
  507. <a class="reference internal" href="compileall.html#module-compileall" title="compileall: Tools for byte-compiling all Python source files in a directory tree."><code class="xref py py-mod docutils literal notranslate"><span class="pre">compileall</span></code></a> as a pre-build step, you must ensure you run it with the
  508. same pycache prefix (if any) that you will use at runtime.</p>
  509. <p>A relative path is interpreted relative to the current working directory.</p>
  510. <p>This value is initially set based on the value of the <a class="reference internal" href="../using/cmdline.html#cmdoption-X"><code class="xref std std-option docutils literal notranslate"><span class="pre">-X</span></code></a>
  511. <code class="docutils literal notranslate"><span class="pre">pycache_prefix=PATH</span></code> command-line option or the
  512. <span class="target" id="index-7"></span><a class="reference internal" href="../using/cmdline.html#envvar-PYTHONPYCACHEPREFIX"><code class="xref std std-envvar docutils literal notranslate"><span class="pre">PYTHONPYCACHEPREFIX</span></code></a> environment variable (command-line takes
  513. precedence). If neither are set, it is <code class="docutils literal notranslate"><span class="pre">None</span></code>.</p>
  514. <div class="versionadded">
  515. <p><span class="versionmodified added">New in version 3.8.</span></p>
  516. </div>
  517. </dd></dl>
  518. <dl class="py function">
  519. <dt class="sig sig-object py" id="sys.excepthook">
  520. <span class="sig-prename descclassname"><span class="pre">sys.</span></span><span class="sig-name descname"><span class="pre">excepthook</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">type</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">value</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">traceback</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#sys.excepthook" title="Link to this definition">¶</a></dt>
  521. <dd><p>This function prints out a given traceback and exception to <code class="docutils literal notranslate"><span class="pre">sys.stderr</span></code>.</p>
  522. <p>When an exception other than <a class="reference internal" href="exceptions.html#SystemExit" title="SystemExit"><code class="xref py py-exc docutils literal notranslate"><span class="pre">SystemExit</span></code></a> is raised and uncaught, the interpreter calls
  523. <code class="docutils literal notranslate"><span class="pre">sys.excepthook</span></code> with three arguments, the exception class, exception
  524. instance, and a traceback object. In an interactive session this happens just
  525. before control is returned to the prompt; in a Python program this happens just
  526. before the program exits. The handling of such top-level exceptions can be
  527. customized by assigning another three-argument function to <code class="docutils literal notranslate"><span class="pre">sys.excepthook</span></code>.</p>
  528. <p class="audit-hook"><p>Raise an auditing event <code class="docutils literal notranslate"><span class="pre">sys.excepthook</span></code> with arguments <code class="docutils literal notranslate"><span class="pre">hook</span></code>,
  529. <code class="docutils literal notranslate"><span class="pre">type</span></code>, <code class="docutils literal notranslate"><span class="pre">value</span></code>, <code class="docutils literal notranslate"><span class="pre">traceback</span></code> when an uncaught exception occurs.
  530. If no hook has been set, <code class="docutils literal notranslate"><span class="pre">hook</span></code> may be <code class="docutils literal notranslate"><span class="pre">None</span></code>. If any hook raises
  531. an exception derived from <a class="reference internal" href="exceptions.html#RuntimeError" title="RuntimeError"><code class="xref py py-class docutils literal notranslate"><span class="pre">RuntimeError</span></code></a> the call to the hook will
  532. be suppressed. Otherwise, the audit hook exception will be reported as
  533. unraisable and <code class="docutils literal notranslate"><span class="pre">sys.excepthook</span></code> will be called.</p>
  534. </p>
  535. <div class="admonition seealso">
  536. <p class="admonition-title">See also</p>
  537. <p>The <a class="reference internal" href="#sys.unraisablehook" title="sys.unraisablehook"><code class="xref py py-func docutils literal notranslate"><span class="pre">sys.unraisablehook()</span></code></a> function handles unraisable exceptions
  538. and the <a class="reference internal" href="threading.html#threading.excepthook" title="threading.excepthook"><code class="xref py py-func docutils literal notranslate"><span class="pre">threading.excepthook()</span></code></a> function handles exception raised
  539. by <a class="reference internal" href="threading.html#threading.Thread.run" title="threading.Thread.run"><code class="xref py py-func docutils literal notranslate"><span class="pre">threading.Thread.run()</span></code></a>.</p>
  540. </div>
  541. </dd></dl>
  542. <dl class="py data">
  543. <dt class="sig sig-object py" id="sys.__breakpointhook__">
  544. <span class="sig-prename descclassname"><span class="pre">sys.</span></span><span class="sig-name descname"><span class="pre">__breakpointhook__</span></span><a class="headerlink" href="#sys.__breakpointhook__" title="Link to this definition">¶</a></dt>
  545. <dt class="sig sig-object py" id="sys.__displayhook__">
  546. <span class="sig-prename descclassname"><span class="pre">sys.</span></span><span class="sig-name descname"><span class="pre">__displayhook__</span></span><a class="headerlink" href="#sys.__displayhook__" title="Link to this definition">¶</a></dt>
  547. <dt class="sig sig-object py" id="sys.__excepthook__">
  548. <span class="sig-prename descclassname"><span class="pre">sys.</span></span><span class="sig-name descname"><span class="pre">__excepthook__</span></span><a class="headerlink" href="#sys.__excepthook__" title="Link to this definition">¶</a></dt>
  549. <dt class="sig sig-object py" id="sys.__unraisablehook__">
  550. <span class="sig-prename descclassname"><span class="pre">sys.</span></span><span class="sig-name descname"><span class="pre">__unraisablehook__</span></span><a class="headerlink" href="#sys.__unraisablehook__" title="Link to this definition">¶</a></dt>
  551. <dd><p>These objects contain the original values of <code class="docutils literal notranslate"><span class="pre">breakpointhook</span></code>,
  552. <code class="docutils literal notranslate"><span class="pre">displayhook</span></code>, <code class="docutils literal notranslate"><span class="pre">excepthook</span></code>, and <code class="docutils literal notranslate"><span class="pre">unraisablehook</span></code> at the start of the
  553. program. They are saved so that <code class="docutils literal notranslate"><span class="pre">breakpointhook</span></code>, <code class="docutils literal notranslate"><span class="pre">displayhook</span></code> and
  554. <code class="docutils literal notranslate"><span class="pre">excepthook</span></code>, <code class="docutils literal notranslate"><span class="pre">unraisablehook</span></code> can be restored in case they happen to
  555. get replaced with broken or alternative objects.</p>
  556. <div class="versionadded">
  557. <p><span class="versionmodified added">New in version 3.7: </span>__breakpointhook__</p>
  558. </div>
  559. <div class="versionadded">
  560. <p><span class="versionmodified added">New in version 3.8: </span>__unraisablehook__</p>
  561. </div>
  562. </dd></dl>
  563. <dl class="py function">
  564. <dt class="sig sig-object py" id="sys.exception">
  565. <span class="sig-prename descclassname"><span class="pre">sys.</span></span><span class="sig-name descname"><span class="pre">exception</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#sys.exception" title="Link to this definition">¶</a></dt>
  566. <dd><p>This function, when called while an exception handler is executing (such as
  567. an <code class="docutils literal notranslate"><span class="pre">except</span></code> or <code class="docutils literal notranslate"><span class="pre">except*</span></code> clause), returns the exception instance that
  568. was caught by this handler. When exception handlers are nested within one
  569. another, only the exception handled by the innermost handler is accessible.</p>
  570. <p>If no exception handler is executing, this function returns <code class="docutils literal notranslate"><span class="pre">None</span></code>.</p>
  571. <div class="versionadded">
  572. <p><span class="versionmodified added">New in version 3.11.</span></p>
  573. </div>
  574. </dd></dl>
  575. <dl class="py function">
  576. <dt class="sig sig-object py" id="sys.exc_info">
  577. <span class="sig-prename descclassname"><span class="pre">sys.</span></span><span class="sig-name descname"><span class="pre">exc_info</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#sys.exc_info" title="Link to this definition">¶</a></dt>
  578. <dd><p>This function returns the old-style representation of the handled
  579. exception. If an exception <code class="docutils literal notranslate"><span class="pre">e</span></code> is currently handled (so
  580. <a class="reference internal" href="#sys.exception" title="sys.exception"><code class="xref py py-func docutils literal notranslate"><span class="pre">exception()</span></code></a> would return <code class="docutils literal notranslate"><span class="pre">e</span></code>), <a class="reference internal" href="#sys.exc_info" title="sys.exc_info"><code class="xref py py-func docutils literal notranslate"><span class="pre">exc_info()</span></code></a> returns the
  581. tuple <code class="docutils literal notranslate"><span class="pre">(type(e),</span> <span class="pre">e,</span> <span class="pre">e.__traceback__)</span></code>.
  582. That is, a tuple containing the type of the exception (a subclass of
  583. <a class="reference internal" href="exceptions.html#BaseException" title="BaseException"><code class="xref py py-exc docutils literal notranslate"><span class="pre">BaseException</span></code></a>), the exception itself, and a <a class="reference internal" href="../reference/datamodel.html#traceback-objects"><span class="std std-ref">traceback
  584. object</span></a> which typically encapsulates the call
  585. stack at the point where the exception last occurred.</p>
  586. <p id="index-8">If no exception is being handled anywhere on the stack, this function
  587. return a tuple containing three <code class="docutils literal notranslate"><span class="pre">None</span></code> values.</p>
  588. <div class="versionchanged">
  589. <p><span class="versionmodified changed">Changed in version 3.11: </span>The <code class="docutils literal notranslate"><span class="pre">type</span></code> and <code class="docutils literal notranslate"><span class="pre">traceback</span></code> fields are now derived from the <code class="docutils literal notranslate"><span class="pre">value</span></code>
  590. (the exception instance), so when an exception is modified while it is
  591. being handled, the changes are reflected in the results of subsequent
  592. calls to <a class="reference internal" href="#sys.exc_info" title="sys.exc_info"><code class="xref py py-func docutils literal notranslate"><span class="pre">exc_info()</span></code></a>.</p>
  593. </div>
  594. </dd></dl>
  595. <dl class="py data">
  596. <dt class="sig sig-object py" id="sys.exec_prefix">
  597. <span class="sig-prename descclassname"><span class="pre">sys.</span></span><span class="sig-name descname"><span class="pre">exec_prefix</span></span><a class="headerlink" href="#sys.exec_prefix" title="Link to this definition">¶</a></dt>
  598. <dd><p>A string giving the site-specific directory prefix where the platform-dependent
  599. Python files are installed; by default, this is also <code class="docutils literal notranslate"><span class="pre">'/usr/local'</span></code>. This can
  600. be set at build time with the <code class="docutils literal notranslate"><span class="pre">--exec-prefix</span></code> argument to the
  601. <strong class="program">configure</strong> script. Specifically, all configuration files (e.g. the
  602. <code class="file docutils literal notranslate"><span class="pre">pyconfig.h</span></code> header file) are installed in the directory
  603. <code class="file docutils literal notranslate"><em><span class="pre">exec_prefix</span></em><span class="pre">/lib/python</span><em><span class="pre">X.Y</span></em><span class="pre">/config</span></code>, and shared library modules are
  604. installed in <code class="file docutils literal notranslate"><em><span class="pre">exec_prefix</span></em><span class="pre">/lib/python</span><em><span class="pre">X.Y</span></em><span class="pre">/lib-dynload</span></code>, where <em>X.Y</em>
  605. is the version number of Python, for example <code class="docutils literal notranslate"><span class="pre">3.2</span></code>.</p>
  606. <div class="admonition note">
  607. <p class="admonition-title">Note</p>
  608. <p>If a <a class="reference internal" href="venv.html#venv-def"><span class="std std-ref">virtual environment</span></a> is in effect, this
  609. value will be changed in <code class="docutils literal notranslate"><span class="pre">site.py</span></code> to point to the virtual environment.
  610. The value for the Python installation will still be available, via
  611. <a class="reference internal" href="#sys.base_exec_prefix" title="sys.base_exec_prefix"><code class="xref py py-data docutils literal notranslate"><span class="pre">base_exec_prefix</span></code></a>.</p>
  612. </div>
  613. </dd></dl>
  614. <dl class="py data">
  615. <dt class="sig sig-object py" id="sys.executable">
  616. <span class="sig-prename descclassname"><span class="pre">sys.</span></span><span class="sig-name descname"><span class="pre">executable</span></span><a class="headerlink" href="#sys.executable" title="Link to this definition">¶</a></dt>
  617. <dd><p>A string giving the absolute path of the executable binary for the Python
  618. interpreter, on systems where this makes sense. If Python is unable to retrieve
  619. the real path to its executable, <a class="reference internal" href="#sys.executable" title="sys.executable"><code class="xref py py-data docutils literal notranslate"><span class="pre">sys.executable</span></code></a> will be an empty string
  620. or <code class="docutils literal notranslate"><span class="pre">None</span></code>.</p>
  621. </dd></dl>
  622. <dl class="py function">
  623. <dt class="sig sig-object py" id="sys.exit">
  624. <span class="sig-prename descclassname"><span class="pre">sys.</span></span><span class="sig-name descname"><span class="pre">exit</span></span><span class="sig-paren">(</span><span class="optional">[</span><em class="sig-param"><span class="n"><span class="pre">arg</span></span></em><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#sys.exit" title="Link to this definition">¶</a></dt>
  625. <dd><p>Raise a <a class="reference internal" href="exceptions.html#SystemExit" title="SystemExit"><code class="xref py py-exc docutils literal notranslate"><span class="pre">SystemExit</span></code></a> exception, signaling an intention to exit the interpreter.</p>
  626. <p>The optional argument <em>arg</em> can be an integer giving the exit status
  627. (defaulting to zero), or another type of object. If it is an integer, zero
  628. is considered “successful termination” and any nonzero value is considered
  629. “abnormal termination” by shells and the like. Most systems require it to be
  630. in the range 0–127, and produce undefined results otherwise. Some systems
  631. have a convention for assigning specific meanings to specific exit codes, but
  632. these are generally underdeveloped; Unix programs generally use 2 for command
  633. line syntax errors and 1 for all other kind of errors. If another type of
  634. object is passed, <code class="docutils literal notranslate"><span class="pre">None</span></code> is equivalent to passing zero, and any other
  635. object is printed to <a class="reference internal" href="#sys.stderr" title="sys.stderr"><code class="xref py py-data docutils literal notranslate"><span class="pre">stderr</span></code></a> and results in an exit code of 1. In
  636. particular, <code class="docutils literal notranslate"><span class="pre">sys.exit(&quot;some</span> <span class="pre">error</span> <span class="pre">message&quot;)</span></code> is a quick way to exit a
  637. program when an error occurs.</p>
  638. <p>Since <a class="reference internal" href="constants.html#exit" title="exit"><code class="xref py py-func docutils literal notranslate"><span class="pre">exit()</span></code></a> ultimately “only” raises an exception, it will only exit
  639. the process when called from the main thread, and the exception is not
  640. intercepted. Cleanup actions specified by finally clauses of <a class="reference internal" href="../reference/compound_stmts.html#try"><code class="xref std std-keyword docutils literal notranslate"><span class="pre">try</span></code></a> statements
  641. are honored, and it is possible to intercept the exit attempt at an outer level.</p>
  642. <div class="versionchanged">
  643. <p><span class="versionmodified changed">Changed in version 3.6: </span>If an error occurs in the cleanup after the Python interpreter
  644. has caught <a class="reference internal" href="exceptions.html#SystemExit" title="SystemExit"><code class="xref py py-exc docutils literal notranslate"><span class="pre">SystemExit</span></code></a> (such as an error flushing buffered data
  645. in the standard streams), the exit status is changed to 120.</p>
  646. </div>
  647. </dd></dl>
  648. <dl class="py data">
  649. <dt class="sig sig-object py" id="sys.flags">
  650. <span class="sig-prename descclassname"><span class="pre">sys.</span></span><span class="sig-name descname"><span class="pre">flags</span></span><a class="headerlink" href="#sys.flags" title="Link to this definition">¶</a></dt>
  651. <dd><p>The <a class="reference internal" href="../glossary.html#term-named-tuple"><span class="xref std std-term">named tuple</span></a> <em>flags</em> exposes the status of command line
  652. flags. The attributes are read only.</p>
  653. <table class="docutils align-default">
  654. <tbody>
  655. <tr class="row-odd"><td><dl class="py attribute">
  656. <dt class="sig sig-object py" id="sys.flags.debug">
  657. <span class="sig-prename descclassname"><span class="pre">flags.</span></span><span class="sig-name descname"><span class="pre">debug</span></span><a class="headerlink" href="#sys.flags.debug" title="Link to this definition">¶</a></dt>
  658. <dd></dd></dl>
  659. </td>
  660. <td><p><a class="reference internal" href="../using/cmdline.html#cmdoption-d"><code class="xref std std-option docutils literal notranslate"><span class="pre">-d</span></code></a></p></td>
  661. </tr>
  662. <tr class="row-even"><td><dl class="py attribute">
  663. <dt class="sig sig-object py" id="sys.flags.inspect">
  664. <span class="sig-prename descclassname"><span class="pre">flags.</span></span><span class="sig-name descname"><span class="pre">inspect</span></span><a class="headerlink" href="#sys.flags.inspect" title="Link to this definition">¶</a></dt>
  665. <dd></dd></dl>
  666. </td>
  667. <td><p><a class="reference internal" href="../using/cmdline.html#cmdoption-i"><code class="xref std std-option docutils literal notranslate"><span class="pre">-i</span></code></a></p></td>
  668. </tr>
  669. <tr class="row-odd"><td><dl class="py attribute">
  670. <dt class="sig sig-object py" id="sys.flags.interactive">
  671. <span class="sig-prename descclassname"><span class="pre">flags.</span></span><span class="sig-name descname"><span class="pre">interactive</span></span><a class="headerlink" href="#sys.flags.interactive" title="Link to this definition">¶</a></dt>
  672. <dd></dd></dl>
  673. </td>
  674. <td><p><a class="reference internal" href="../using/cmdline.html#cmdoption-i"><code class="xref std std-option docutils literal notranslate"><span class="pre">-i</span></code></a></p></td>
  675. </tr>
  676. <tr class="row-even"><td><dl class="py attribute">
  677. <dt class="sig sig-object py" id="sys.flags.isolated">
  678. <span class="sig-prename descclassname"><span class="pre">flags.</span></span><span class="sig-name descname"><span class="pre">isolated</span></span><a class="headerlink" href="#sys.flags.isolated" title="Link to this definition">¶</a></dt>
  679. <dd></dd></dl>
  680. </td>
  681. <td><p><a class="reference internal" href="../using/cmdline.html#cmdoption-I"><code class="xref std std-option docutils literal notranslate"><span class="pre">-I</span></code></a></p></td>
  682. </tr>
  683. <tr class="row-odd"><td><dl class="py attribute">
  684. <dt class="sig sig-object py" id="sys.flags.optimize">
  685. <span class="sig-prename descclassname"><span class="pre">flags.</span></span><span class="sig-name descname"><span class="pre">optimize</span></span><a class="headerlink" href="#sys.flags.optimize" title="Link to this definition">¶</a></dt>
  686. <dd></dd></dl>
  687. </td>
  688. <td><p><a class="reference internal" href="../using/cmdline.html#cmdoption-O"><code class="xref std std-option docutils literal notranslate"><span class="pre">-O</span></code></a> or <a class="reference internal" href="../using/cmdline.html#cmdoption-OO"><code class="xref std std-option docutils literal notranslate"><span class="pre">-OO</span></code></a></p></td>
  689. </tr>
  690. <tr class="row-even"><td><dl class="py attribute">
  691. <dt class="sig sig-object py" id="sys.flags.dont_write_bytecode">
  692. <span class="sig-prename descclassname"><span class="pre">flags.</span></span><span class="sig-name descname"><span class="pre">dont_write_bytecode</span></span><a class="headerlink" href="#sys.flags.dont_write_bytecode" title="Link to this definition">¶</a></dt>
  693. <dd></dd></dl>
  694. </td>
  695. <td><p><a class="reference internal" href="../using/cmdline.html#cmdoption-B"><code class="xref std std-option docutils literal notranslate"><span class="pre">-B</span></code></a></p></td>
  696. </tr>
  697. <tr class="row-odd"><td><dl class="py attribute">
  698. <dt class="sig sig-object py" id="sys.flags.no_user_site">
  699. <span class="sig-prename descclassname"><span class="pre">flags.</span></span><span class="sig-name descname"><span class="pre">no_user_site</span></span><a class="headerlink" href="#sys.flags.no_user_site" title="Link to this definition">¶</a></dt>
  700. <dd></dd></dl>
  701. </td>
  702. <td><p><a class="reference internal" href="../using/cmdline.html#cmdoption-s"><code class="xref std std-option docutils literal notranslate"><span class="pre">-s</span></code></a></p></td>
  703. </tr>
  704. <tr class="row-even"><td><dl class="py attribute">
  705. <dt class="sig sig-object py" id="sys.flags.no_site">
  706. <span class="sig-prename descclassname"><span class="pre">flags.</span></span><span class="sig-name descname"><span class="pre">no_site</span></span><a class="headerlink" href="#sys.flags.no_site" title="Link to this definition">¶</a></dt>
  707. <dd></dd></dl>
  708. </td>
  709. <td><p><a class="reference internal" href="../using/cmdline.html#cmdoption-S"><code class="xref std std-option docutils literal notranslate"><span class="pre">-S</span></code></a></p></td>
  710. </tr>
  711. <tr class="row-odd"><td><dl class="py attribute">
  712. <dt class="sig sig-object py" id="sys.flags.ignore_environment">
  713. <span class="sig-prename descclassname"><span class="pre">flags.</span></span><span class="sig-name descname"><span class="pre">ignore_environment</span></span><a class="headerlink" href="#sys.flags.ignore_environment" title="Link to this definition">¶</a></dt>
  714. <dd></dd></dl>
  715. </td>
  716. <td><p><a class="reference internal" href="../using/cmdline.html#cmdoption-E"><code class="xref std std-option docutils literal notranslate"><span class="pre">-E</span></code></a></p></td>
  717. </tr>
  718. <tr class="row-even"><td><dl class="py attribute">
  719. <dt class="sig sig-object py" id="sys.flags.verbose">
  720. <span class="sig-prename descclassname"><span class="pre">flags.</span></span><span class="sig-name descname"><span class="pre">verbose</span></span><a class="headerlink" href="#sys.flags.verbose" title="Link to this definition">¶</a></dt>
  721. <dd></dd></dl>
  722. </td>
  723. <td><p><a class="reference internal" href="../using/cmdline.html#cmdoption-v"><code class="xref std std-option docutils literal notranslate"><span class="pre">-v</span></code></a></p></td>
  724. </tr>
  725. <tr class="row-odd"><td><dl class="py attribute">
  726. <dt class="sig sig-object py" id="sys.flags.bytes_warning">
  727. <span class="sig-prename descclassname"><span class="pre">flags.</span></span><span class="sig-name descname"><span class="pre">bytes_warning</span></span><a class="headerlink" href="#sys.flags.bytes_warning" title="Link to this definition">¶</a></dt>
  728. <dd></dd></dl>
  729. </td>
  730. <td><p><a class="reference internal" href="../using/cmdline.html#cmdoption-b"><code class="xref std std-option docutils literal notranslate"><span class="pre">-b</span></code></a></p></td>
  731. </tr>
  732. <tr class="row-even"><td><dl class="py attribute">
  733. <dt class="sig sig-object py" id="sys.flags.quiet">
  734. <span class="sig-prename descclassname"><span class="pre">flags.</span></span><span class="sig-name descname"><span class="pre">quiet</span></span><a class="headerlink" href="#sys.flags.quiet" title="Link to this definition">¶</a></dt>
  735. <dd></dd></dl>
  736. </td>
  737. <td><p><a class="reference internal" href="../using/cmdline.html#cmdoption-q"><code class="xref std std-option docutils literal notranslate"><span class="pre">-q</span></code></a></p></td>
  738. </tr>
  739. <tr class="row-odd"><td><dl class="py attribute">
  740. <dt class="sig sig-object py" id="sys.flags.hash_randomization">
  741. <span class="sig-prename descclassname"><span class="pre">flags.</span></span><span class="sig-name descname"><span class="pre">hash_randomization</span></span><a class="headerlink" href="#sys.flags.hash_randomization" title="Link to this definition">¶</a></dt>
  742. <dd></dd></dl>
  743. </td>
  744. <td><p><a class="reference internal" href="../using/cmdline.html#cmdoption-R"><code class="xref std std-option docutils literal notranslate"><span class="pre">-R</span></code></a></p></td>
  745. </tr>
  746. <tr class="row-even"><td><dl class="py attribute">
  747. <dt class="sig sig-object py" id="sys.flags.dev_mode">
  748. <span class="sig-prename descclassname"><span class="pre">flags.</span></span><span class="sig-name descname"><span class="pre">dev_mode</span></span><a class="headerlink" href="#sys.flags.dev_mode" title="Link to this definition">¶</a></dt>
  749. <dd></dd></dl>
  750. </td>
  751. <td><p><a class="reference internal" href="../using/cmdline.html#cmdoption-X"><code class="xref std std-option docutils literal notranslate"><span class="pre">-X</span> <span class="pre">dev</span></code></a> (<a class="reference internal" href="devmode.html#devmode"><span class="std std-ref">Python Development Mode</span></a>)</p></td>
  752. </tr>
  753. <tr class="row-odd"><td><dl class="py attribute">
  754. <dt class="sig sig-object py" id="sys.flags.utf8_mode">
  755. <span class="sig-prename descclassname"><span class="pre">flags.</span></span><span class="sig-name descname"><span class="pre">utf8_mode</span></span><a class="headerlink" href="#sys.flags.utf8_mode" title="Link to this definition">¶</a></dt>
  756. <dd></dd></dl>
  757. </td>
  758. <td><p><a class="reference internal" href="../using/cmdline.html#cmdoption-X"><code class="xref std std-option docutils literal notranslate"><span class="pre">-X</span> <span class="pre">utf8</span></code></a></p></td>
  759. </tr>
  760. <tr class="row-even"><td><dl class="py attribute">
  761. <dt class="sig sig-object py" id="sys.flags.safe_path">
  762. <span class="sig-prename descclassname"><span class="pre">flags.</span></span><span class="sig-name descname"><span class="pre">safe_path</span></span><a class="headerlink" href="#sys.flags.safe_path" title="Link to this definition">¶</a></dt>
  763. <dd></dd></dl>
  764. </td>
  765. <td><p><a class="reference internal" href="../using/cmdline.html#cmdoption-P"><code class="xref std std-option docutils literal notranslate"><span class="pre">-P</span></code></a></p></td>
  766. </tr>
  767. <tr class="row-odd"><td><dl class="py attribute">
  768. <dt class="sig sig-object py" id="sys.flags.int_max_str_digits">
  769. <span class="sig-prename descclassname"><span class="pre">flags.</span></span><span class="sig-name descname"><span class="pre">int_max_str_digits</span></span><a class="headerlink" href="#sys.flags.int_max_str_digits" title="Link to this definition">¶</a></dt>
  770. <dd></dd></dl>
  771. </td>
  772. <td><p><a class="reference internal" href="../using/cmdline.html#cmdoption-X"><code class="xref std std-option docutils literal notranslate"><span class="pre">-X</span> <span class="pre">int_max_str_digits</span></code></a>
  773. (<a class="reference internal" href="stdtypes.html#int-max-str-digits"><span class="std std-ref">integer string conversion length limitation</span></a>)</p></td>
  774. </tr>
  775. <tr class="row-even"><td><dl class="py attribute">
  776. <dt class="sig sig-object py" id="sys.flags.warn_default_encoding">
  777. <span class="sig-prename descclassname"><span class="pre">flags.</span></span><span class="sig-name descname"><span class="pre">warn_default_encoding</span></span><a class="headerlink" href="#sys.flags.warn_default_encoding" title="Link to this definition">¶</a></dt>
  778. <dd></dd></dl>
  779. </td>
  780. <td><p><a class="reference internal" href="../using/cmdline.html#cmdoption-X"><code class="xref std std-option docutils literal notranslate"><span class="pre">-X</span> <span class="pre">warn_default_encoding</span></code></a></p></td>
  781. </tr>
  782. </tbody>
  783. </table>
  784. <div class="versionchanged">
  785. <p><span class="versionmodified changed">Changed in version 3.2: </span>Added <code class="docutils literal notranslate"><span class="pre">quiet</span></code> attribute for the new <a class="reference internal" href="../using/cmdline.html#cmdoption-q"><code class="xref std std-option docutils literal notranslate"><span class="pre">-q</span></code></a> flag.</p>
  786. </div>
  787. <div class="versionadded">
  788. <p><span class="versionmodified added">New in version 3.2.3: </span>The <code class="docutils literal notranslate"><span class="pre">hash_randomization</span></code> attribute.</p>
  789. </div>
  790. <div class="versionchanged">
  791. <p><span class="versionmodified changed">Changed in version 3.3: </span>Removed obsolete <code class="docutils literal notranslate"><span class="pre">division_warning</span></code> attribute.</p>
  792. </div>
  793. <div class="versionchanged">
  794. <p><span class="versionmodified changed">Changed in version 3.4: </span>Added <code class="docutils literal notranslate"><span class="pre">isolated</span></code> attribute for <a class="reference internal" href="../using/cmdline.html#cmdoption-I"><code class="xref std std-option docutils literal notranslate"><span class="pre">-I</span></code></a> <code class="docutils literal notranslate"><span class="pre">isolated</span></code> flag.</p>
  795. </div>
  796. <div class="versionchanged">
  797. <p><span class="versionmodified changed">Changed in version 3.7: </span>Added the <code class="docutils literal notranslate"><span class="pre">dev_mode</span></code> attribute for the new <a class="reference internal" href="devmode.html#devmode"><span class="std std-ref">Python Development
  798. Mode</span></a> and the <code class="docutils literal notranslate"><span class="pre">utf8_mode</span></code> attribute for the new <a class="reference internal" href="../using/cmdline.html#cmdoption-X"><code class="xref std std-option docutils literal notranslate"><span class="pre">-X</span></code></a>
  799. <code class="docutils literal notranslate"><span class="pre">utf8</span></code> flag.</p>
  800. </div>
  801. <div class="versionchanged">
  802. <p><span class="versionmodified changed">Changed in version 3.10: </span>Added <code class="docutils literal notranslate"><span class="pre">warn_default_encoding</span></code> attribute for <a class="reference internal" href="../using/cmdline.html#cmdoption-X"><code class="xref std std-option docutils literal notranslate"><span class="pre">-X</span></code></a> <code class="docutils literal notranslate"><span class="pre">warn_default_encoding</span></code> flag.</p>
  803. </div>
  804. <div class="versionchanged">
  805. <p><span class="versionmodified changed">Changed in version 3.11: </span>Added the <code class="docutils literal notranslate"><span class="pre">safe_path</span></code> attribute for <a class="reference internal" href="../using/cmdline.html#cmdoption-P"><code class="xref std std-option docutils literal notranslate"><span class="pre">-P</span></code></a> option.</p>
  806. </div>
  807. <div class="versionchanged">
  808. <p><span class="versionmodified changed">Changed in version 3.11: </span>Added the <code class="docutils literal notranslate"><span class="pre">int_max_str_digits</span></code> attribute.</p>
  809. </div>
  810. </dd></dl>
  811. <dl class="py data">
  812. <dt class="sig sig-object py" id="sys.float_info">
  813. <span class="sig-prename descclassname"><span class="pre">sys.</span></span><span class="sig-name descname"><span class="pre">float_info</span></span><a class="headerlink" href="#sys.float_info" title="Link to this definition">¶</a></dt>
  814. <dd><p>A <a class="reference internal" href="../glossary.html#term-named-tuple"><span class="xref std std-term">named tuple</span></a> holding information about the float type. It
  815. contains low level information about the precision and internal
  816. representation. The values correspond to the various floating-point
  817. constants defined in the standard header file <code class="file docutils literal notranslate"><span class="pre">float.h</span></code> for the ‘C’
  818. programming language; see section 5.2.4.2.2 of the 1999 ISO/IEC C standard
  819. <a class="reference internal" href="#c99" id="id1"><span>[C99]</span></a>, ‘Characteristics of floating types’, for details.</p>
  820. <table class="docutils align-default" id="id2">
  821. <caption><span class="caption-text">Attributes of the <code class="xref py py-data docutils literal notranslate"><span class="pre">float_info</span></code> <a class="reference internal" href="../glossary.html#term-named-tuple"><span class="xref std std-term">named tuple</span></a></span><a class="headerlink" href="#id2" title="Link to this table">¶</a></caption>
  822. <thead>
  823. <tr class="row-odd"><th class="head"><p>attribute</p></th>
  824. <th class="head"><p>float.h macro</p></th>
  825. <th class="head"><p>explanation</p></th>
  826. </tr>
  827. </thead>
  828. <tbody>
  829. <tr class="row-even"><td><dl class="py attribute">
  830. <dt class="sig sig-object py" id="sys.float_info.epsilon">
  831. <span class="sig-prename descclassname"><span class="pre">float_info.</span></span><span class="sig-name descname"><span class="pre">epsilon</span></span><a class="headerlink" href="#sys.float_info.epsilon" title="Link to this definition">¶</a></dt>
  832. <dd></dd></dl>
  833. </td>
  834. <td><p><code class="xref c c-macro docutils literal notranslate"><span class="pre">DBL_EPSILON</span></code></p></td>
  835. <td><p>difference between 1.0 and the least value greater than 1.0 that is
  836. representable as a float.</p>
  837. <p>See also <a class="reference internal" href="math.html#math.ulp" title="math.ulp"><code class="xref py py-func docutils literal notranslate"><span class="pre">math.ulp()</span></code></a>.</p>
  838. </td>
  839. </tr>
  840. <tr class="row-odd"><td><dl class="py attribute">
  841. <dt class="sig sig-object py" id="sys.float_info.dig">
  842. <span class="sig-prename descclassname"><span class="pre">float_info.</span></span><span class="sig-name descname"><span class="pre">dig</span></span><a class="headerlink" href="#sys.float_info.dig" title="Link to this definition">¶</a></dt>
  843. <dd></dd></dl>
  844. </td>
  845. <td><p><code class="xref c c-macro docutils literal notranslate"><span class="pre">DBL_DIG</span></code></p></td>
  846. <td><p>The maximum number of decimal digits that can be faithfully
  847. represented in a float; see below.</p></td>
  848. </tr>
  849. <tr class="row-even"><td><dl class="py attribute">
  850. <dt class="sig sig-object py" id="sys.float_info.mant_dig">
  851. <span class="sig-prename descclassname"><span class="pre">float_info.</span></span><span class="sig-name descname"><span class="pre">mant_dig</span></span><a class="headerlink" href="#sys.float_info.mant_dig" title="Link to this definition">¶</a></dt>
  852. <dd></dd></dl>
  853. </td>
  854. <td><p><code class="xref c c-macro docutils literal notranslate"><span class="pre">DBL_MANT_DIG</span></code></p></td>
  855. <td><p>Float precision: the number of base-<code class="docutils literal notranslate"><span class="pre">radix</span></code> digits in the
  856. significand of a float.</p></td>
  857. </tr>
  858. <tr class="row-odd"><td><dl class="py attribute">
  859. <dt class="sig sig-object py" id="sys.float_info.max">
  860. <span class="sig-prename descclassname"><span class="pre">float_info.</span></span><span class="sig-name descname"><span class="pre">max</span></span><a class="headerlink" href="#sys.float_info.max" title="Link to this definition">¶</a></dt>
  861. <dd></dd></dl>
  862. </td>
  863. <td><p><code class="xref c c-macro docutils literal notranslate"><span class="pre">DBL_MAX</span></code></p></td>
  864. <td><p>The maximum representable positive finite float.</p></td>
  865. </tr>
  866. <tr class="row-even"><td><dl class="py attribute">
  867. <dt class="sig sig-object py" id="sys.float_info.max_exp">
  868. <span class="sig-prename descclassname"><span class="pre">float_info.</span></span><span class="sig-name descname"><span class="pre">max_exp</span></span><a class="headerlink" href="#sys.float_info.max_exp" title="Link to this definition">¶</a></dt>
  869. <dd></dd></dl>
  870. </td>
  871. <td><p><code class="xref c c-macro docutils literal notranslate"><span class="pre">DBL_MAX_EXP</span></code></p></td>
  872. <td><p>The maximum integer <em>e</em> such that <code class="docutils literal notranslate"><span class="pre">radix**(e-1)</span></code> is a representable
  873. finite float.</p></td>
  874. </tr>
  875. <tr class="row-odd"><td><dl class="py attribute">
  876. <dt class="sig sig-object py" id="sys.float_info.max_10_exp">
  877. <span class="sig-prename descclassname"><span class="pre">float_info.</span></span><span class="sig-name descname"><span class="pre">max_10_exp</span></span><a class="headerlink" href="#sys.float_info.max_10_exp" title="Link to this definition">¶</a></dt>
  878. <dd></dd></dl>
  879. </td>
  880. <td><p><code class="xref c c-macro docutils literal notranslate"><span class="pre">DBL_MAX_10_EXP</span></code></p></td>
  881. <td><p>The maximum integer <em>e</em> such that <code class="docutils literal notranslate"><span class="pre">10**e</span></code> is in the range of
  882. representable finite floats.</p></td>
  883. </tr>
  884. <tr class="row-even"><td><dl class="py attribute">
  885. <dt class="sig sig-object py" id="sys.float_info.min">
  886. <span class="sig-prename descclassname"><span class="pre">float_info.</span></span><span class="sig-name descname"><span class="pre">min</span></span><a class="headerlink" href="#sys.float_info.min" title="Link to this definition">¶</a></dt>
  887. <dd></dd></dl>
  888. </td>
  889. <td><p><code class="xref c c-macro docutils literal notranslate"><span class="pre">DBL_MIN</span></code></p></td>
  890. <td><p>The minimum representable positive <em>normalized</em> float.</p>
  891. <p>Use <a class="reference internal" href="math.html#math.ulp" title="math.ulp"><code class="xref py py-func docutils literal notranslate"><span class="pre">math.ulp(0.0)</span></code></a> to get the smallest positive
  892. <em>denormalized</em> representable float.</p>
  893. </td>
  894. </tr>
  895. <tr class="row-odd"><td><dl class="py attribute">
  896. <dt class="sig sig-object py" id="sys.float_info.min_exp">
  897. <span class="sig-prename descclassname"><span class="pre">float_info.</span></span><span class="sig-name descname"><span class="pre">min_exp</span></span><a class="headerlink" href="#sys.float_info.min_exp" title="Link to this definition">¶</a></dt>
  898. <dd></dd></dl>
  899. </td>
  900. <td><p><code class="xref c c-macro docutils literal notranslate"><span class="pre">DBL_MIN_EXP</span></code></p></td>
  901. <td><p>The minimum integer <em>e</em> such that <code class="docutils literal notranslate"><span class="pre">radix**(e-1)</span></code> is a normalized
  902. float.</p></td>
  903. </tr>
  904. <tr class="row-even"><td><dl class="py attribute">
  905. <dt class="sig sig-object py" id="sys.float_info.min_10_exp">
  906. <span class="sig-prename descclassname"><span class="pre">float_info.</span></span><span class="sig-name descname"><span class="pre">min_10_exp</span></span><a class="headerlink" href="#sys.float_info.min_10_exp" title="Link to this definition">¶</a></dt>
  907. <dd></dd></dl>
  908. </td>
  909. <td><p><code class="xref c c-macro docutils literal notranslate"><span class="pre">DBL_MIN_10_EXP</span></code></p></td>
  910. <td><p>The minimum integer <em>e</em> such that <code class="docutils literal notranslate"><span class="pre">10**e</span></code> is a normalized float.</p></td>
  911. </tr>
  912. <tr class="row-odd"><td><dl class="py attribute">
  913. <dt class="sig sig-object py" id="sys.float_info.radix">
  914. <span class="sig-prename descclassname"><span class="pre">float_info.</span></span><span class="sig-name descname"><span class="pre">radix</span></span><a class="headerlink" href="#sys.float_info.radix" title="Link to this definition">¶</a></dt>
  915. <dd></dd></dl>
  916. </td>
  917. <td><p><code class="xref c c-macro docutils literal notranslate"><span class="pre">FLT_RADIX</span></code></p></td>
  918. <td><p>The radix of exponent representation.</p></td>
  919. </tr>
  920. <tr class="row-even"><td><dl class="py attribute">
  921. <dt class="sig sig-object py" id="sys.float_info.rounds">
  922. <span class="sig-prename descclassname"><span class="pre">float_info.</span></span><span class="sig-name descname"><span class="pre">rounds</span></span><a class="headerlink" href="#sys.float_info.rounds" title="Link to this definition">¶</a></dt>
  923. <dd></dd></dl>
  924. </td>
  925. <td><p><code class="xref c c-macro docutils literal notranslate"><span class="pre">FLT_ROUNDS</span></code></p></td>
  926. <td><p>An integer representing the rounding mode for floating-point arithmetic.
  927. This reflects the value of the system <code class="xref c c-macro docutils literal notranslate"><span class="pre">FLT_ROUNDS</span></code> macro
  928. at interpreter startup time:</p>
  929. <ul class="simple">
  930. <li><p><code class="docutils literal notranslate"><span class="pre">-1</span></code>: indeterminable</p></li>
  931. <li><p><code class="docutils literal notranslate"><span class="pre">0</span></code>: toward zero</p></li>
  932. <li><p><code class="docutils literal notranslate"><span class="pre">1</span></code>: to nearest</p></li>
  933. <li><p><code class="docutils literal notranslate"><span class="pre">2</span></code>: toward positive infinity</p></li>
  934. <li><p><code class="docutils literal notranslate"><span class="pre">3</span></code>: toward negative infinity</p></li>
  935. </ul>
  936. <p>All other values for <code class="xref c c-macro docutils literal notranslate"><span class="pre">FLT_ROUNDS</span></code> characterize
  937. implementation-defined rounding behavior.</p>
  938. </td>
  939. </tr>
  940. </tbody>
  941. </table>
  942. <p>The attribute <a class="reference internal" href="#sys.float_info.dig" title="sys.float_info.dig"><code class="xref py py-attr docutils literal notranslate"><span class="pre">sys.float_info.dig</span></code></a> needs further explanation. If
  943. <code class="docutils literal notranslate"><span class="pre">s</span></code> is any string representing a decimal number with at most
  944. <code class="xref py py-attr docutils literal notranslate"><span class="pre">sys.float_info.dig</span></code> significant digits, then converting <code class="docutils literal notranslate"><span class="pre">s</span></code> to a
  945. float and back again will recover a string representing the same decimal
  946. value:</p>
  947. <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">import</span> <span class="nn">sys</span>
  948. <span class="gp">&gt;&gt;&gt; </span><span class="n">sys</span><span class="o">.</span><span class="n">float_info</span><span class="o">.</span><span class="n">dig</span>
  949. <span class="go">15</span>
  950. <span class="gp">&gt;&gt;&gt; </span><span class="n">s</span> <span class="o">=</span> <span class="s1">&#39;3.14159265358979&#39;</span> <span class="c1"># decimal string with 15 significant digits</span>
  951. <span class="gp">&gt;&gt;&gt; </span><span class="nb">format</span><span class="p">(</span><span class="nb">float</span><span class="p">(</span><span class="n">s</span><span class="p">),</span> <span class="s1">&#39;.15g&#39;</span><span class="p">)</span> <span class="c1"># convert to float and back -&gt; same value</span>
  952. <span class="go">&#39;3.14159265358979&#39;</span>
  953. </pre></div>
  954. </div>
  955. <p>But for strings with more than <a class="reference internal" href="#sys.float_info.dig" title="sys.float_info.dig"><code class="xref py py-attr docutils literal notranslate"><span class="pre">sys.float_info.dig</span></code></a> significant digits,
  956. this isn’t always true:</p>
  957. <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">s</span> <span class="o">=</span> <span class="s1">&#39;9876543211234567&#39;</span> <span class="c1"># 16 significant digits is too many!</span>
  958. <span class="gp">&gt;&gt;&gt; </span><span class="nb">format</span><span class="p">(</span><span class="nb">float</span><span class="p">(</span><span class="n">s</span><span class="p">),</span> <span class="s1">&#39;.16g&#39;</span><span class="p">)</span> <span class="c1"># conversion changes value</span>
  959. <span class="go">&#39;9876543211234568&#39;</span>
  960. </pre></div>
  961. </div>
  962. </dd></dl>
  963. <dl class="py data">
  964. <dt class="sig sig-object py" id="sys.float_repr_style">
  965. <span class="sig-prename descclassname"><span class="pre">sys.</span></span><span class="sig-name descname"><span class="pre">float_repr_style</span></span><a class="headerlink" href="#sys.float_repr_style" title="Link to this definition">¶</a></dt>
  966. <dd><p>A string indicating how the <a class="reference internal" href="functions.html#repr" title="repr"><code class="xref py py-func docutils literal notranslate"><span class="pre">repr()</span></code></a> function behaves for
  967. floats. If the string has value <code class="docutils literal notranslate"><span class="pre">'short'</span></code> then for a finite
  968. float <code class="docutils literal notranslate"><span class="pre">x</span></code>, <code class="docutils literal notranslate"><span class="pre">repr(x)</span></code> aims to produce a short string with the
  969. property that <code class="docutils literal notranslate"><span class="pre">float(repr(x))</span> <span class="pre">==</span> <span class="pre">x</span></code>. This is the usual behaviour
  970. in Python 3.1 and later. Otherwise, <code class="docutils literal notranslate"><span class="pre">float_repr_style</span></code> has value
  971. <code class="docutils literal notranslate"><span class="pre">'legacy'</span></code> and <code class="docutils literal notranslate"><span class="pre">repr(x)</span></code> behaves in the same way as it did in
  972. versions of Python prior to 3.1.</p>
  973. <div class="versionadded">
  974. <p><span class="versionmodified added">New in version 3.1.</span></p>
  975. </div>
  976. </dd></dl>
  977. <dl class="py function">
  978. <dt class="sig sig-object py" id="sys.getallocatedblocks">
  979. <span class="sig-prename descclassname"><span class="pre">sys.</span></span><span class="sig-name descname"><span class="pre">getallocatedblocks</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#sys.getallocatedblocks" title="Link to this definition">¶</a></dt>
  980. <dd><p>Return the number of memory blocks currently allocated by the interpreter,
  981. regardless of their size. This function is mainly useful for tracking
  982. and debugging memory leaks. Because of the interpreter’s internal
  983. caches, the result can vary from call to call; you may have to call
  984. <a class="reference internal" href="#sys._clear_type_cache" title="sys._clear_type_cache"><code class="xref py py-func docutils literal notranslate"><span class="pre">_clear_type_cache()</span></code></a> and <a class="reference internal" href="gc.html#gc.collect" title="gc.collect"><code class="xref py py-func docutils literal notranslate"><span class="pre">gc.collect()</span></code></a> to get more
  985. predictable results.</p>
  986. <p>If a Python build or implementation cannot reasonably compute this
  987. information, <a class="reference internal" href="#sys.getallocatedblocks" title="sys.getallocatedblocks"><code class="xref py py-func docutils literal notranslate"><span class="pre">getallocatedblocks()</span></code></a> is allowed to return 0 instead.</p>
  988. <div class="versionadded">
  989. <p><span class="versionmodified added">New in version 3.4.</span></p>
  990. </div>
  991. </dd></dl>
  992. <dl class="py function">
  993. <dt class="sig sig-object py" id="sys.getunicodeinternedsize">
  994. <span class="sig-prename descclassname"><span class="pre">sys.</span></span><span class="sig-name descname"><span class="pre">getunicodeinternedsize</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#sys.getunicodeinternedsize" title="Link to this definition">¶</a></dt>
  995. <dd><p>Return the number of unicode objects that have been interned.</p>
  996. <div class="versionadded">
  997. <p><span class="versionmodified added">New in version 3.12.</span></p>
  998. </div>
  999. </dd></dl>
  1000. <dl class="py function">
  1001. <dt class="sig sig-object py" id="sys.getandroidapilevel">
  1002. <span class="sig-prename descclassname"><span class="pre">sys.</span></span><span class="sig-name descname"><span class="pre">getandroidapilevel</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#sys.getandroidapilevel" title="Link to this definition">¶</a></dt>
  1003. <dd><p>Return the build time API version of Android as an integer.</p>
  1004. <div class="availability docutils container">
  1005. <p><a class="reference internal" href="intro.html#availability"><span class="std std-ref">Availability</span></a>: Android.</p>
  1006. </div>
  1007. <div class="versionadded">
  1008. <p><span class="versionmodified added">New in version 3.7.</span></p>
  1009. </div>
  1010. </dd></dl>
  1011. <dl class="py function">
  1012. <dt class="sig sig-object py" id="sys.getdefaultencoding">
  1013. <span class="sig-prename descclassname"><span class="pre">sys.</span></span><span class="sig-name descname"><span class="pre">getdefaultencoding</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#sys.getdefaultencoding" title="Link to this definition">¶</a></dt>
  1014. <dd><p>Return the name of the current default string encoding used by the Unicode
  1015. implementation.</p>
  1016. </dd></dl>
  1017. <dl class="py function">
  1018. <dt class="sig sig-object py" id="sys.getdlopenflags">
  1019. <span class="sig-prename descclassname"><span class="pre">sys.</span></span><span class="sig-name descname"><span class="pre">getdlopenflags</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#sys.getdlopenflags" title="Link to this definition">¶</a></dt>
  1020. <dd><p>Return the current value of the flags that are used for
  1021. <code class="xref c c-func docutils literal notranslate"><span class="pre">dlopen()</span></code> calls. Symbolic names for the flag values can be
  1022. found in the <a class="reference internal" href="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 (<code class="samp docutils literal notranslate"><span class="pre">RTLD_</span><em><span class="pre">xxx</span></em></code> constants, e.g.
  1023. <a class="reference internal" href="os.html#os.RTLD_LAZY" title="os.RTLD_LAZY"><code class="xref py py-const docutils literal notranslate"><span class="pre">os.RTLD_LAZY</span></code></a>).</p>
  1024. <div class="availability docutils container">
  1025. <p><a class="reference internal" href="intro.html#availability"><span class="std std-ref">Availability</span></a>: Unix.</p>
  1026. </div>
  1027. </dd></dl>
  1028. <dl class="py function">
  1029. <dt class="sig sig-object py" id="sys.getfilesystemencoding">
  1030. <span class="sig-prename descclassname"><span class="pre">sys.</span></span><span class="sig-name descname"><span class="pre">getfilesystemencoding</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#sys.getfilesystemencoding" title="Link to this definition">¶</a></dt>
  1031. <dd><p>Get the <a class="reference internal" href="../glossary.html#term-filesystem-encoding-and-error-handler"><span class="xref std std-term">filesystem encoding</span></a>:
  1032. the encoding used with the <a class="reference internal" href="../glossary.html#term-filesystem-encoding-and-error-handler"><span class="xref std std-term">filesystem error handler</span></a> to convert between Unicode filenames and bytes
  1033. filenames. The filesystem error handler is returned from
  1034. <a class="reference internal" href="#sys.getfilesystemencodeerrors" title="sys.getfilesystemencodeerrors"><code class="xref py py-func docutils literal notranslate"><span class="pre">getfilesystemencodeerrors()</span></code></a>.</p>
  1035. <p>For best compatibility, str should be used for filenames in all cases,
  1036. although representing filenames as bytes is also supported. Functions
  1037. accepting or returning filenames should support either str or bytes and
  1038. internally convert to the system’s preferred representation.</p>
  1039. <p><a class="reference internal" href="os.html#os.fsencode" title="os.fsencode"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.fsencode()</span></code></a> and <a class="reference internal" href="os.html#os.fsdecode" title="os.fsdecode"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.fsdecode()</span></code></a> should be used to ensure that
  1040. the correct encoding and errors mode are used.</p>
  1041. <p>The <a class="reference internal" href="../glossary.html#term-filesystem-encoding-and-error-handler"><span class="xref std std-term">filesystem encoding and error handler</span></a> are configured at Python
  1042. startup by the <a class="reference internal" href="../c-api/init_config.html#c.PyConfig_Read" title="PyConfig_Read"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyConfig_Read()</span></code></a> function: see
  1043. <a class="reference internal" href="../c-api/init_config.html#c.PyConfig.filesystem_encoding" title="PyConfig.filesystem_encoding"><code class="xref c c-member docutils literal notranslate"><span class="pre">filesystem_encoding</span></code></a> and
  1044. <a class="reference internal" href="../c-api/init_config.html#c.PyConfig.filesystem_errors" title="PyConfig.filesystem_errors"><code class="xref c c-member docutils literal notranslate"><span class="pre">filesystem_errors</span></code></a> members of <a class="reference internal" href="../c-api/init_config.html#c.PyConfig" title="PyConfig"><code class="xref c c-type docutils literal notranslate"><span class="pre">PyConfig</span></code></a>.</p>
  1045. <div class="versionchanged">
  1046. <p><span class="versionmodified changed">Changed in version 3.2: </span><a class="reference internal" href="#sys.getfilesystemencoding" title="sys.getfilesystemencoding"><code class="xref py py-func docutils literal notranslate"><span class="pre">getfilesystemencoding()</span></code></a> result cannot be <code class="docutils literal notranslate"><span class="pre">None</span></code> anymore.</p>
  1047. </div>
  1048. <div class="versionchanged">
  1049. <p><span class="versionmodified changed">Changed in version 3.6: </span>Windows is no longer guaranteed to return <code class="docutils literal notranslate"><span class="pre">'mbcs'</span></code>. See <span class="target" id="index-9"></span><a class="pep reference external" href="https://peps.python.org/pep-0529/"><strong>PEP 529</strong></a>
  1050. and <a class="reference internal" href="#sys._enablelegacywindowsfsencoding" title="sys._enablelegacywindowsfsencoding"><code class="xref py py-func docutils literal notranslate"><span class="pre">_enablelegacywindowsfsencoding()</span></code></a> for more information.</p>
  1051. </div>
  1052. <div class="versionchanged">
  1053. <p><span class="versionmodified changed">Changed in version 3.7: </span>Return <code class="docutils literal notranslate"><span class="pre">'utf-8'</span></code> if the <a class="reference internal" href="os.html#utf8-mode"><span class="std std-ref">Python UTF-8 Mode</span></a> is
  1054. enabled.</p>
  1055. </div>
  1056. </dd></dl>
  1057. <dl class="py function">
  1058. <dt class="sig sig-object py" id="sys.getfilesystemencodeerrors">
  1059. <span class="sig-prename descclassname"><span class="pre">sys.</span></span><span class="sig-name descname"><span class="pre">getfilesystemencodeerrors</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#sys.getfilesystemencodeerrors" title="Link to this definition">¶</a></dt>
  1060. <dd><p>Get the <a class="reference internal" href="../glossary.html#term-filesystem-encoding-and-error-handler"><span class="xref std std-term">filesystem error handler</span></a>: the error handler used with the <a class="reference internal" href="../glossary.html#term-filesystem-encoding-and-error-handler"><span class="xref std std-term">filesystem encoding</span></a> to convert between Unicode
  1061. filenames and bytes filenames. The filesystem encoding is returned from
  1062. <a class="reference internal" href="#sys.getfilesystemencoding" title="sys.getfilesystemencoding"><code class="xref py py-func docutils literal notranslate"><span class="pre">getfilesystemencoding()</span></code></a>.</p>
  1063. <p><a class="reference internal" href="os.html#os.fsencode" title="os.fsencode"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.fsencode()</span></code></a> and <a class="reference internal" href="os.html#os.fsdecode" title="os.fsdecode"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.fsdecode()</span></code></a> should be used to ensure that
  1064. the correct encoding and errors mode are used.</p>
  1065. <p>The <a class="reference internal" href="../glossary.html#term-filesystem-encoding-and-error-handler"><span class="xref std std-term">filesystem encoding and error handler</span></a> are configured at Python
  1066. startup by the <a class="reference internal" href="../c-api/init_config.html#c.PyConfig_Read" title="PyConfig_Read"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyConfig_Read()</span></code></a> function: see
  1067. <a class="reference internal" href="../c-api/init_config.html#c.PyConfig.filesystem_encoding" title="PyConfig.filesystem_encoding"><code class="xref c c-member docutils literal notranslate"><span class="pre">filesystem_encoding</span></code></a> and
  1068. <a class="reference internal" href="../c-api/init_config.html#c.PyConfig.filesystem_errors" title="PyConfig.filesystem_errors"><code class="xref c c-member docutils literal notranslate"><span class="pre">filesystem_errors</span></code></a> members of <a class="reference internal" href="../c-api/init_config.html#c.PyConfig" title="PyConfig"><code class="xref c c-type docutils literal notranslate"><span class="pre">PyConfig</span></code></a>.</p>
  1069. <div class="versionadded">
  1070. <p><span class="versionmodified added">New in version 3.6.</span></p>
  1071. </div>
  1072. </dd></dl>
  1073. <dl class="py function">
  1074. <dt class="sig sig-object py" id="sys.get_int_max_str_digits">
  1075. <span class="sig-prename descclassname"><span class="pre">sys.</span></span><span class="sig-name descname"><span class="pre">get_int_max_str_digits</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#sys.get_int_max_str_digits" title="Link to this definition">¶</a></dt>
  1076. <dd><p>Returns the current value for the <a class="reference internal" href="stdtypes.html#int-max-str-digits"><span class="std std-ref">integer string conversion length
  1077. limitation</span></a>. See also <a class="reference internal" href="#sys.set_int_max_str_digits" title="sys.set_int_max_str_digits"><code class="xref py py-func docutils literal notranslate"><span class="pre">set_int_max_str_digits()</span></code></a>.</p>
  1078. <div class="versionadded">
  1079. <p><span class="versionmodified added">New in version 3.11.</span></p>
  1080. </div>
  1081. </dd></dl>
  1082. <dl class="py function">
  1083. <dt class="sig sig-object py" id="sys.getrefcount">
  1084. <span class="sig-prename descclassname"><span class="pre">sys.</span></span><span class="sig-name descname"><span class="pre">getrefcount</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">object</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#sys.getrefcount" title="Link to this definition">¶</a></dt>
  1085. <dd><p>Return the reference count of the <em>object</em>. The count returned is generally one
  1086. higher than you might expect, because it includes the (temporary) reference as
  1087. an argument to <a class="reference internal" href="#sys.getrefcount" title="sys.getrefcount"><code class="xref py py-func docutils literal notranslate"><span class="pre">getrefcount()</span></code></a>.</p>
  1088. <p>Note that the returned value may not actually reflect how many
  1089. references to the object are actually held. For example, some
  1090. objects are “immortal” and have a very high refcount that does not
  1091. reflect the actual number of references. Consequently, do not rely
  1092. on the returned value to be accurate, other than a value of 0 or 1.</p>
  1093. <div class="versionchanged">
  1094. <p><span class="versionmodified changed">Changed in version 3.12: </span>Immortal objects have very large refcounts that do not match
  1095. the actual number of references to the object.</p>
  1096. </div>
  1097. </dd></dl>
  1098. <dl class="py function">
  1099. <dt class="sig sig-object py" id="sys.getrecursionlimit">
  1100. <span class="sig-prename descclassname"><span class="pre">sys.</span></span><span class="sig-name descname"><span class="pre">getrecursionlimit</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#sys.getrecursionlimit" title="Link to this definition">¶</a></dt>
  1101. <dd><p>Return the current value of the recursion limit, the maximum depth of the Python
  1102. interpreter stack. This limit prevents infinite recursion from causing an
  1103. overflow of the C stack and crashing Python. It can be set by
  1104. <a class="reference internal" href="#sys.setrecursionlimit" title="sys.setrecursionlimit"><code class="xref py py-func docutils literal notranslate"><span class="pre">setrecursionlimit()</span></code></a>.</p>
  1105. </dd></dl>
  1106. <dl class="py function">
  1107. <dt class="sig sig-object py" id="sys.getsizeof">
  1108. <span class="sig-prename descclassname"><span class="pre">sys.</span></span><span class="sig-name descname"><span class="pre">getsizeof</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">object</span></span></em><span class="optional">[</span>, <em class="sig-param"><span class="n"><span class="pre">default</span></span></em><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#sys.getsizeof" title="Link to this definition">¶</a></dt>
  1109. <dd><p>Return the size of an object in bytes. The object can be any type of
  1110. object. All built-in objects will return correct results, but this
  1111. does not have to hold true for third-party extensions as it is implementation
  1112. specific.</p>
  1113. <p>Only the memory consumption directly attributed to the object is
  1114. accounted for, not the memory consumption of objects it refers to.</p>
  1115. <p>If given, <em>default</em> will be returned if the object does not provide means to
  1116. retrieve the size. Otherwise a <a class="reference internal" href="exceptions.html#TypeError" title="TypeError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">TypeError</span></code></a> will be raised.</p>
  1117. <p><a class="reference internal" href="#sys.getsizeof" title="sys.getsizeof"><code class="xref py py-func docutils literal notranslate"><span class="pre">getsizeof()</span></code></a> calls the object’s <code class="docutils literal notranslate"><span class="pre">__sizeof__</span></code> method and adds an
  1118. additional garbage collector overhead if the object is managed by the garbage
  1119. collector.</p>
  1120. <p>See <a class="reference external" href="https://code.activestate.com/recipes/577504/">recursive sizeof recipe</a>
  1121. for an example of using <a class="reference internal" href="#sys.getsizeof" title="sys.getsizeof"><code class="xref py py-func docutils literal notranslate"><span class="pre">getsizeof()</span></code></a> recursively to find the size of
  1122. containers and all their contents.</p>
  1123. </dd></dl>
  1124. <dl class="py function">
  1125. <dt class="sig sig-object py" id="sys.getswitchinterval">
  1126. <span class="sig-prename descclassname"><span class="pre">sys.</span></span><span class="sig-name descname"><span class="pre">getswitchinterval</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#sys.getswitchinterval" title="Link to this definition">¶</a></dt>
  1127. <dd><p>Return the interpreter’s “thread switch interval”; see
  1128. <a class="reference internal" href="#sys.setswitchinterval" title="sys.setswitchinterval"><code class="xref py py-func docutils literal notranslate"><span class="pre">setswitchinterval()</span></code></a>.</p>
  1129. <div class="versionadded">
  1130. <p><span class="versionmodified added">New in version 3.2.</span></p>
  1131. </div>
  1132. </dd></dl>
  1133. <dl class="py function">
  1134. <dt class="sig sig-object py" id="sys._getframe">
  1135. <span class="sig-prename descclassname"><span class="pre">sys.</span></span><span class="sig-name descname"><span class="pre">_getframe</span></span><span class="sig-paren">(</span><span class="optional">[</span><em class="sig-param"><span class="n"><span class="pre">depth</span></span></em><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#sys._getframe" title="Link to this definition">¶</a></dt>
  1136. <dd><p>Return a frame object from the call stack. If optional integer <em>depth</em> is
  1137. given, return the frame object that many calls below the top of the stack. If
  1138. that is deeper than the call stack, <a class="reference internal" href="exceptions.html#ValueError" title="ValueError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">ValueError</span></code></a> is raised. The default
  1139. for <em>depth</em> is zero, returning the frame at the top of the call stack.</p>
  1140. <p class="audit-hook">Raises an <a class="reference internal" href="#auditing"><span class="std std-ref">auditing event</span></a> <code class="docutils literal notranslate"><span class="pre">sys._getframe</span></code> with argument <code class="docutils literal notranslate"><span class="pre">frame</span></code>.</p>
  1141. <div class="impl-detail compound">
  1142. <p><strong>CPython implementation detail:</strong> This function should be used for internal and specialized purposes only.
  1143. It is not guaranteed to exist in all implementations of Python.</p>
  1144. </div>
  1145. </dd></dl>
  1146. <dl class="py function">
  1147. <dt class="sig sig-object py" id="sys._getframemodulename">
  1148. <span class="sig-prename descclassname"><span class="pre">sys.</span></span><span class="sig-name descname"><span class="pre">_getframemodulename</span></span><span class="sig-paren">(</span><span class="optional">[</span><em class="sig-param"><span class="n"><span class="pre">depth</span></span></em><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#sys._getframemodulename" title="Link to this definition">¶</a></dt>
  1149. <dd><p>Return the name of a module from the call stack. If optional integer <em>depth</em>
  1150. is given, return the module that many calls below the top of the stack. If
  1151. that is deeper than the call stack, or if the module is unidentifiable,
  1152. <code class="docutils literal notranslate"><span class="pre">None</span></code> is returned. The default for <em>depth</em> is zero, returning the
  1153. module at the top of the call stack.</p>
  1154. <p class="audit-hook">Raises an <a class="reference internal" href="#auditing"><span class="std std-ref">auditing event</span></a> <code class="docutils literal notranslate"><span class="pre">sys._getframemodulename</span></code> with argument <code class="docutils literal notranslate"><span class="pre">depth</span></code>.</p>
  1155. <div class="impl-detail compound">
  1156. <p><strong>CPython implementation detail:</strong> This function should be used for internal and specialized purposes only.
  1157. It is not guaranteed to exist in all implementations of Python.</p>
  1158. </div>
  1159. </dd></dl>
  1160. <dl class="py function">
  1161. <dt class="sig sig-object py" id="sys.getprofile">
  1162. <span class="sig-prename descclassname"><span class="pre">sys.</span></span><span class="sig-name descname"><span class="pre">getprofile</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#sys.getprofile" title="Link to this definition">¶</a></dt>
  1163. <dd><p id="index-10">Get the profiler function as set by <a class="reference internal" href="#sys.setprofile" title="sys.setprofile"><code class="xref py py-func docutils literal notranslate"><span class="pre">setprofile()</span></code></a>.</p>
  1164. </dd></dl>
  1165. <dl class="py function">
  1166. <dt class="sig sig-object py" id="sys.gettrace">
  1167. <span class="sig-prename descclassname"><span class="pre">sys.</span></span><span class="sig-name descname"><span class="pre">gettrace</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#sys.gettrace" title="Link to this definition">¶</a></dt>
  1168. <dd><p id="index-11">Get the trace function as set by <a class="reference internal" href="#sys.settrace" title="sys.settrace"><code class="xref py py-func docutils literal notranslate"><span class="pre">settrace()</span></code></a>.</p>
  1169. <div class="impl-detail compound">
  1170. <p><strong>CPython implementation detail:</strong> The <a class="reference internal" href="#sys.gettrace" title="sys.gettrace"><code class="xref py py-func docutils literal notranslate"><span class="pre">gettrace()</span></code></a> function is intended only for implementing debuggers,
  1171. profilers, coverage tools and the like. Its behavior is part of the
  1172. implementation platform, rather than part of the language definition, and
  1173. thus may not be available in all Python implementations.</p>
  1174. </div>
  1175. </dd></dl>
  1176. <dl class="py function">
  1177. <dt class="sig sig-object py" id="sys.getwindowsversion">
  1178. <span class="sig-prename descclassname"><span class="pre">sys.</span></span><span class="sig-name descname"><span class="pre">getwindowsversion</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#sys.getwindowsversion" title="Link to this definition">¶</a></dt>
  1179. <dd><p>Return a named tuple describing the Windows version
  1180. currently running. The named elements are <em>major</em>, <em>minor</em>,
  1181. <em>build</em>, <em>platform</em>, <em>service_pack</em>, <em>service_pack_minor</em>,
  1182. <em>service_pack_major</em>, <em>suite_mask</em>, <em>product_type</em> and
  1183. <em>platform_version</em>. <em>service_pack</em> contains a string,
  1184. <em>platform_version</em> a 3-tuple and all other values are
  1185. integers. The components can also be accessed by name, so
  1186. <code class="docutils literal notranslate"><span class="pre">sys.getwindowsversion()[0]</span></code> is equivalent to
  1187. <code class="docutils literal notranslate"><span class="pre">sys.getwindowsversion().major</span></code>. For compatibility with prior
  1188. versions, only the first 5 elements are retrievable by indexing.</p>
  1189. <p><em>platform</em> will be <code class="docutils literal notranslate"><span class="pre">2</span></code> (VER_PLATFORM_WIN32_NT).</p>
  1190. <p><em>product_type</em> may be one of the following values:</p>
  1191. <table class="docutils align-default">
  1192. <thead>
  1193. <tr class="row-odd"><th class="head"><p>Constant</p></th>
  1194. <th class="head"><p>Meaning</p></th>
  1195. </tr>
  1196. </thead>
  1197. <tbody>
  1198. <tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">1</span></code> (VER_NT_WORKSTATION)</p></td>
  1199. <td><p>The system is a workstation.</p></td>
  1200. </tr>
  1201. <tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">2</span></code> (VER_NT_DOMAIN_CONTROLLER)</p></td>
  1202. <td><p>The system is a domain
  1203. controller.</p></td>
  1204. </tr>
  1205. <tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">3</span></code> (VER_NT_SERVER)</p></td>
  1206. <td><p>The system is a server, but not
  1207. a domain controller.</p></td>
  1208. </tr>
  1209. </tbody>
  1210. </table>
  1211. <p>This function wraps the Win32 <code class="xref c c-func docutils literal notranslate"><span class="pre">GetVersionEx()</span></code> function; see the
  1212. Microsoft documentation on <code class="xref c c-func docutils literal notranslate"><span class="pre">OSVERSIONINFOEX()</span></code> for more information
  1213. about these fields.</p>
  1214. <p><em>platform_version</em> returns the major version, minor version and
  1215. build number of the current operating system, rather than the version that
  1216. is being emulated for the process. It is intended for use in logging rather
  1217. than for feature detection.</p>
  1218. <div class="admonition note">
  1219. <p class="admonition-title">Note</p>
  1220. <p><em>platform_version</em> derives the version from kernel32.dll which can be of a different
  1221. version than the OS version. Please use <a class="reference internal" href="platform.html#module-platform" title="platform: Retrieves as much platform identifying data as possible."><code class="xref py py-mod docutils literal notranslate"><span class="pre">platform</span></code></a> module for achieving accurate
  1222. OS version.</p>
  1223. </div>
  1224. <div class="availability docutils container">
  1225. <p><a class="reference internal" href="intro.html#availability"><span class="std std-ref">Availability</span></a>: Windows.</p>
  1226. </div>
  1227. <div class="versionchanged">
  1228. <p><span class="versionmodified changed">Changed in version 3.2: </span>Changed to a named tuple and added <em>service_pack_minor</em>,
  1229. <em>service_pack_major</em>, <em>suite_mask</em>, and <em>product_type</em>.</p>
  1230. </div>
  1231. <div class="versionchanged">
  1232. <p><span class="versionmodified changed">Changed in version 3.6: </span>Added <em>platform_version</em></p>
  1233. </div>
  1234. </dd></dl>
  1235. <dl class="py function">
  1236. <dt class="sig sig-object py" id="sys.get_asyncgen_hooks">
  1237. <span class="sig-prename descclassname"><span class="pre">sys.</span></span><span class="sig-name descname"><span class="pre">get_asyncgen_hooks</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#sys.get_asyncgen_hooks" title="Link to this definition">¶</a></dt>
  1238. <dd><p>Returns an <em>asyncgen_hooks</em> object, which is similar to a
  1239. <a class="reference internal" href="collections.html#collections.namedtuple" title="collections.namedtuple"><code class="xref py py-class docutils literal notranslate"><span class="pre">namedtuple</span></code></a> of the form <code class="docutils literal notranslate"><span class="pre">(firstiter,</span> <span class="pre">finalizer)</span></code>,
  1240. where <em>firstiter</em> and <em>finalizer</em> are expected to be either <code class="docutils literal notranslate"><span class="pre">None</span></code> or
  1241. functions which take an <a class="reference internal" href="../glossary.html#term-asynchronous-generator-iterator"><span class="xref std std-term">asynchronous generator iterator</span></a> as an
  1242. argument, and are used to schedule finalization of an asynchronous
  1243. generator by an event loop.</p>
  1244. <div class="versionadded">
  1245. <p><span class="versionmodified added">New in version 3.6: </span>See <span class="target" id="index-12"></span><a class="pep reference external" href="https://peps.python.org/pep-0525/"><strong>PEP 525</strong></a> for more details.</p>
  1246. </div>
  1247. <div class="admonition note">
  1248. <p class="admonition-title">Note</p>
  1249. <p>This function has been added on a provisional basis (see <span class="target" id="index-13"></span><a class="pep reference external" href="https://peps.python.org/pep-0411/"><strong>PEP 411</strong></a>
  1250. for details.)</p>
  1251. </div>
  1252. </dd></dl>
  1253. <dl class="py function">
  1254. <dt class="sig sig-object py" id="sys.get_coroutine_origin_tracking_depth">
  1255. <span class="sig-prename descclassname"><span class="pre">sys.</span></span><span class="sig-name descname"><span class="pre">get_coroutine_origin_tracking_depth</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#sys.get_coroutine_origin_tracking_depth" title="Link to this definition">¶</a></dt>
  1256. <dd><p>Get the current coroutine origin tracking depth, as set by
  1257. <a class="reference internal" href="#sys.set_coroutine_origin_tracking_depth" title="sys.set_coroutine_origin_tracking_depth"><code class="xref py py-func docutils literal notranslate"><span class="pre">set_coroutine_origin_tracking_depth()</span></code></a>.</p>
  1258. <div class="versionadded">
  1259. <p><span class="versionmodified added">New in version 3.7.</span></p>
  1260. </div>
  1261. <div class="admonition note">
  1262. <p class="admonition-title">Note</p>
  1263. <p>This function has been added on a provisional basis (see <span class="target" id="index-14"></span><a class="pep reference external" href="https://peps.python.org/pep-0411/"><strong>PEP 411</strong></a>
  1264. for details.) Use it only for debugging purposes.</p>
  1265. </div>
  1266. </dd></dl>
  1267. <dl class="py data">
  1268. <dt class="sig sig-object py" id="sys.hash_info">
  1269. <span class="sig-prename descclassname"><span class="pre">sys.</span></span><span class="sig-name descname"><span class="pre">hash_info</span></span><a class="headerlink" href="#sys.hash_info" title="Link to this definition">¶</a></dt>
  1270. <dd><p>A <a class="reference internal" href="../glossary.html#term-named-tuple"><span class="xref std std-term">named tuple</span></a> giving parameters of the numeric hash
  1271. implementation. For more details about hashing of numeric types, see
  1272. <a class="reference internal" href="stdtypes.html#numeric-hash"><span class="std std-ref">Hashing of numeric types</span></a>.</p>
  1273. <dl class="py attribute">
  1274. <dt class="sig sig-object py" id="sys.hash_info.width">
  1275. <span class="sig-prename descclassname"><span class="pre">hash_info.</span></span><span class="sig-name descname"><span class="pre">width</span></span><a class="headerlink" href="#sys.hash_info.width" title="Link to this definition">¶</a></dt>
  1276. <dd><p>The width in bits used for hash values</p>
  1277. </dd></dl>
  1278. <dl class="py attribute">
  1279. <dt class="sig sig-object py" id="sys.hash_info.modulus">
  1280. <span class="sig-prename descclassname"><span class="pre">hash_info.</span></span><span class="sig-name descname"><span class="pre">modulus</span></span><a class="headerlink" href="#sys.hash_info.modulus" title="Link to this definition">¶</a></dt>
  1281. <dd><p>The prime modulus P used for numeric hash scheme</p>
  1282. </dd></dl>
  1283. <dl class="py attribute">
  1284. <dt class="sig sig-object py" id="sys.hash_info.inf">
  1285. <span class="sig-prename descclassname"><span class="pre">hash_info.</span></span><span class="sig-name descname"><span class="pre">inf</span></span><a class="headerlink" href="#sys.hash_info.inf" title="Link to this definition">¶</a></dt>
  1286. <dd><p>The hash value returned for a positive infinity</p>
  1287. </dd></dl>
  1288. <dl class="py attribute">
  1289. <dt class="sig sig-object py" id="sys.hash_info.nan">
  1290. <span class="sig-prename descclassname"><span class="pre">hash_info.</span></span><span class="sig-name descname"><span class="pre">nan</span></span><a class="headerlink" href="#sys.hash_info.nan" title="Link to this definition">¶</a></dt>
  1291. <dd><p>(This attribute is no longer used)</p>
  1292. </dd></dl>
  1293. <dl class="py attribute">
  1294. <dt class="sig sig-object py" id="sys.hash_info.imag">
  1295. <span class="sig-prename descclassname"><span class="pre">hash_info.</span></span><span class="sig-name descname"><span class="pre">imag</span></span><a class="headerlink" href="#sys.hash_info.imag" title="Link to this definition">¶</a></dt>
  1296. <dd><p>The multiplier used for the imaginary part of a complex number</p>
  1297. </dd></dl>
  1298. <dl class="py attribute">
  1299. <dt class="sig sig-object py" id="sys.hash_info.algorithm">
  1300. <span class="sig-prename descclassname"><span class="pre">hash_info.</span></span><span class="sig-name descname"><span class="pre">algorithm</span></span><a class="headerlink" href="#sys.hash_info.algorithm" title="Link to this definition">¶</a></dt>
  1301. <dd><p>The name of the algorithm for hashing of str, bytes, and memoryview</p>
  1302. </dd></dl>
  1303. <dl class="py attribute">
  1304. <dt class="sig sig-object py" id="sys.hash_info.hash_bits">
  1305. <span class="sig-prename descclassname"><span class="pre">hash_info.</span></span><span class="sig-name descname"><span class="pre">hash_bits</span></span><a class="headerlink" href="#sys.hash_info.hash_bits" title="Link to this definition">¶</a></dt>
  1306. <dd><p>The internal output size of the hash algorithm</p>
  1307. </dd></dl>
  1308. <dl class="py attribute">
  1309. <dt class="sig sig-object py" id="sys.hash_info.seed_bits">
  1310. <span class="sig-prename descclassname"><span class="pre">hash_info.</span></span><span class="sig-name descname"><span class="pre">seed_bits</span></span><a class="headerlink" href="#sys.hash_info.seed_bits" title="Link to this definition">¶</a></dt>
  1311. <dd><p>The size of the seed key of the hash algorithm</p>
  1312. </dd></dl>
  1313. <div class="versionadded">
  1314. <p><span class="versionmodified added">New in version 3.2.</span></p>
  1315. </div>
  1316. <div class="versionchanged">
  1317. <p><span class="versionmodified changed">Changed in version 3.4: </span>Added <em>algorithm</em>, <em>hash_bits</em> and <em>seed_bits</em></p>
  1318. </div>
  1319. </dd></dl>
  1320. <dl class="py data">
  1321. <dt class="sig sig-object py" id="sys.hexversion">
  1322. <span class="sig-prename descclassname"><span class="pre">sys.</span></span><span class="sig-name descname"><span class="pre">hexversion</span></span><a class="headerlink" href="#sys.hexversion" title="Link to this definition">¶</a></dt>
  1323. <dd><p>The version number encoded as a single integer. This is guaranteed to increase
  1324. with each version, including proper support for non-production releases. For
  1325. example, to test that the Python interpreter is at least version 1.5.2, use:</p>
  1326. <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="k">if</span> <span class="n">sys</span><span class="o">.</span><span class="n">hexversion</span> <span class="o">&gt;=</span> <span class="mh">0x010502F0</span><span class="p">:</span>
  1327. <span class="c1"># use some advanced feature</span>
  1328. <span class="o">...</span>
  1329. <span class="k">else</span><span class="p">:</span>
  1330. <span class="c1"># use an alternative implementation or warn the user</span>
  1331. <span class="o">...</span>
  1332. </pre></div>
  1333. </div>
  1334. <p>This is called <code class="docutils literal notranslate"><span class="pre">hexversion</span></code> since it only really looks meaningful when viewed
  1335. as the result of passing it to the built-in <a class="reference internal" href="functions.html#hex" title="hex"><code class="xref py py-func docutils literal notranslate"><span class="pre">hex()</span></code></a> function. The
  1336. <a class="reference internal" href="../glossary.html#term-named-tuple"><span class="xref std std-term">named tuple</span></a> <a class="reference internal" href="#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> may be used for a more
  1337. human-friendly encoding of the same information.</p>
  1338. <p>More details of <code class="docutils literal notranslate"><span class="pre">hexversion</span></code> can be found at <a class="reference internal" href="../c-api/apiabiversion.html#apiabiversion"><span class="std std-ref">API and ABI Versioning</span></a>.</p>
  1339. </dd></dl>
  1340. <dl class="py data">
  1341. <dt class="sig sig-object py" id="sys.implementation">
  1342. <span class="sig-prename descclassname"><span class="pre">sys.</span></span><span class="sig-name descname"><span class="pre">implementation</span></span><a class="headerlink" href="#sys.implementation" title="Link to this definition">¶</a></dt>
  1343. <dd><p>An object containing information about the implementation of the
  1344. currently running Python interpreter. The following attributes are
  1345. required to exist in all Python implementations.</p>
  1346. <p><em>name</em> is the implementation’s identifier, e.g. <code class="docutils literal notranslate"><span class="pre">'cpython'</span></code>. The actual
  1347. string is defined by the Python implementation, but it is guaranteed to be
  1348. lower case.</p>
  1349. <p><em>version</em> is a named tuple, in the same format as
  1350. <a class="reference internal" href="#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>. It represents the version of the Python
  1351. <em>implementation</em>. This has a distinct meaning from the specific
  1352. version of the Python <em>language</em> to which the currently running
  1353. interpreter conforms, which <code class="docutils literal notranslate"><span class="pre">sys.version_info</span></code> represents. For
  1354. example, for PyPy 1.8 <code class="docutils literal notranslate"><span class="pre">sys.implementation.version</span></code> might be
  1355. <code class="docutils literal notranslate"><span class="pre">sys.version_info(1,</span> <span class="pre">8,</span> <span class="pre">0,</span> <span class="pre">'final',</span> <span class="pre">0)</span></code>, whereas <code class="docutils literal notranslate"><span class="pre">sys.version_info</span></code>
  1356. would be <code class="docutils literal notranslate"><span class="pre">sys.version_info(2,</span> <span class="pre">7,</span> <span class="pre">2,</span> <span class="pre">'final',</span> <span class="pre">0)</span></code>. For CPython they
  1357. are the same value, since it is the reference implementation.</p>
  1358. <p><em>hexversion</em> is the implementation version in hexadecimal format, like
  1359. <a class="reference internal" href="#sys.hexversion" title="sys.hexversion"><code class="xref py py-data docutils literal notranslate"><span class="pre">sys.hexversion</span></code></a>.</p>
  1360. <p><em>cache_tag</em> is the tag used by the import machinery in the filenames of
  1361. cached modules. By convention, it would be a composite of the
  1362. implementation’s name and version, like <code class="docutils literal notranslate"><span class="pre">'cpython-33'</span></code>. However, a
  1363. Python implementation may use some other value if appropriate. If
  1364. <code class="docutils literal notranslate"><span class="pre">cache_tag</span></code> is set to <code class="docutils literal notranslate"><span class="pre">None</span></code>, it indicates that module caching should
  1365. be disabled.</p>
  1366. <p><a class="reference internal" href="#sys.implementation" title="sys.implementation"><code class="xref py py-data docutils literal notranslate"><span class="pre">sys.implementation</span></code></a> may contain additional attributes specific to
  1367. the Python implementation. These non-standard attributes must start with
  1368. an underscore, and are not described here. Regardless of its contents,
  1369. <a class="reference internal" href="#sys.implementation" title="sys.implementation"><code class="xref py py-data docutils literal notranslate"><span class="pre">sys.implementation</span></code></a> will not change during a run of the interpreter,
  1370. nor between implementation versions. (It may change between Python
  1371. language versions, however.) See <span class="target" id="index-15"></span><a class="pep reference external" href="https://peps.python.org/pep-0421/"><strong>PEP 421</strong></a> for more information.</p>
  1372. <div class="versionadded">
  1373. <p><span class="versionmodified added">New in version 3.3.</span></p>
  1374. </div>
  1375. <div class="admonition note">
  1376. <p class="admonition-title">Note</p>
  1377. <p>The addition of new required attributes must go through the normal PEP
  1378. process. See <span class="target" id="index-16"></span><a class="pep reference external" href="https://peps.python.org/pep-0421/"><strong>PEP 421</strong></a> for more information.</p>
  1379. </div>
  1380. </dd></dl>
  1381. <dl class="py data">
  1382. <dt class="sig sig-object py" id="sys.int_info">
  1383. <span class="sig-prename descclassname"><span class="pre">sys.</span></span><span class="sig-name descname"><span class="pre">int_info</span></span><a class="headerlink" href="#sys.int_info" title="Link to this definition">¶</a></dt>
  1384. <dd><p>A <a class="reference internal" href="../glossary.html#term-named-tuple"><span class="xref std std-term">named tuple</span></a> that holds information about Python’s internal
  1385. representation of integers. The attributes are read only.</p>
  1386. <dl class="py attribute">
  1387. <dt class="sig sig-object py" id="sys.int_info.bits_per_digit">
  1388. <span class="sig-prename descclassname"><span class="pre">int_info.</span></span><span class="sig-name descname"><span class="pre">bits_per_digit</span></span><a class="headerlink" href="#sys.int_info.bits_per_digit" title="Link to this definition">¶</a></dt>
  1389. <dd><p>The number of bits held in each digit.
  1390. Python integers are stored internally in base <code class="docutils literal notranslate"><span class="pre">2**int_info.bits_per_digit</span></code>.</p>
  1391. </dd></dl>
  1392. <dl class="py attribute">
  1393. <dt class="sig sig-object py" id="sys.int_info.sizeof_digit">
  1394. <span class="sig-prename descclassname"><span class="pre">int_info.</span></span><span class="sig-name descname"><span class="pre">sizeof_digit</span></span><a class="headerlink" href="#sys.int_info.sizeof_digit" title="Link to this definition">¶</a></dt>
  1395. <dd><p>The size in bytes of the C type used to represent a digit.</p>
  1396. </dd></dl>
  1397. <dl class="py attribute">
  1398. <dt class="sig sig-object py" id="sys.int_info.default_max_str_digits">
  1399. <span class="sig-prename descclassname"><span class="pre">int_info.</span></span><span class="sig-name descname"><span class="pre">default_max_str_digits</span></span><a class="headerlink" href="#sys.int_info.default_max_str_digits" title="Link to this definition">¶</a></dt>
  1400. <dd><p>The default value for <a class="reference internal" href="#sys.get_int_max_str_digits" title="sys.get_int_max_str_digits"><code class="xref py py-func docutils literal notranslate"><span class="pre">sys.get_int_max_str_digits()</span></code></a>
  1401. when it is not otherwise explicitly configured.</p>
  1402. </dd></dl>
  1403. <dl class="py attribute">
  1404. <dt class="sig sig-object py" id="sys.int_info.str_digits_check_threshold">
  1405. <span class="sig-prename descclassname"><span class="pre">int_info.</span></span><span class="sig-name descname"><span class="pre">str_digits_check_threshold</span></span><a class="headerlink" href="#sys.int_info.str_digits_check_threshold" title="Link to this definition">¶</a></dt>
  1406. <dd><p>The minimum non-zero value for <a class="reference internal" href="#sys.set_int_max_str_digits" title="sys.set_int_max_str_digits"><code class="xref py py-func docutils literal notranslate"><span class="pre">sys.set_int_max_str_digits()</span></code></a>,
  1407. <span class="target" id="index-17"></span><a class="reference internal" href="../using/cmdline.html#envvar-PYTHONINTMAXSTRDIGITS"><code class="xref std std-envvar docutils literal notranslate"><span class="pre">PYTHONINTMAXSTRDIGITS</span></code></a>, or <a class="reference internal" href="../using/cmdline.html#cmdoption-X"><code class="xref std std-option docutils literal notranslate"><span class="pre">-X</span> <span class="pre">int_max_str_digits</span></code></a>.</p>
  1408. </dd></dl>
  1409. <div class="versionadded">
  1410. <p><span class="versionmodified added">New in version 3.1.</span></p>
  1411. </div>
  1412. <div class="versionchanged">
  1413. <p><span class="versionmodified changed">Changed in version 3.11: </span>Added <a class="reference internal" href="#sys.int_info.default_max_str_digits" title="sys.int_info.default_max_str_digits"><code class="xref py py-attr docutils literal notranslate"><span class="pre">default_max_str_digits</span></code></a> and
  1414. <a class="reference internal" href="#sys.int_info.str_digits_check_threshold" title="sys.int_info.str_digits_check_threshold"><code class="xref py py-attr docutils literal notranslate"><span class="pre">str_digits_check_threshold</span></code></a>.</p>
  1415. </div>
  1416. </dd></dl>
  1417. <dl class="py data">
  1418. <dt class="sig sig-object py" id="sys.__interactivehook__">
  1419. <span class="sig-prename descclassname"><span class="pre">sys.</span></span><span class="sig-name descname"><span class="pre">__interactivehook__</span></span><a class="headerlink" href="#sys.__interactivehook__" title="Link to this definition">¶</a></dt>
  1420. <dd><p>When this attribute exists, its value is automatically called (with no
  1421. arguments) when the interpreter is launched in <a class="reference internal" href="../tutorial/interpreter.html#tut-interactive"><span class="std std-ref">interactive mode</span></a>. This is done after the <span class="target" id="index-18"></span><a class="reference internal" href="../using/cmdline.html#envvar-PYTHONSTARTUP"><code class="xref std std-envvar docutils literal notranslate"><span class="pre">PYTHONSTARTUP</span></code></a> file is
  1422. read, so that you can set this hook there. The <a class="reference internal" href="site.html#module-site" title="site: Module responsible for site-specific configuration."><code class="xref py py-mod docutils literal notranslate"><span class="pre">site</span></code></a> module
  1423. <a class="reference internal" href="site.html#rlcompleter-config"><span class="std std-ref">sets this</span></a>.</p>
  1424. <p class="audit-hook"><p>Raises an <a class="reference internal" href="#auditing"><span class="std std-ref">auditing event</span></a>
  1425. <code class="docutils literal notranslate"><span class="pre">cpython.run_interactivehook</span></code> with the hook object as the argument when
  1426. the hook is called on startup.</p>
  1427. </p>
  1428. <div class="versionadded">
  1429. <p><span class="versionmodified added">New in version 3.4.</span></p>
  1430. </div>
  1431. </dd></dl>
  1432. <dl class="py function">
  1433. <dt class="sig sig-object py" id="sys.intern">
  1434. <span class="sig-prename descclassname"><span class="pre">sys.</span></span><span class="sig-name descname"><span class="pre">intern</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">string</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#sys.intern" title="Link to this definition">¶</a></dt>
  1435. <dd><p>Enter <em>string</em> in the table of “interned” strings and return the interned string
  1436. – which is <em>string</em> itself or a copy. Interning strings is useful to gain a
  1437. little performance on dictionary lookup – if the keys in a dictionary are
  1438. interned, and the lookup key is interned, the key comparisons (after hashing)
  1439. can be done by a pointer compare instead of a string compare. Normally, the
  1440. names used in Python programs are automatically interned, and the dictionaries
  1441. used to hold module, class or instance attributes have interned keys.</p>
  1442. <p>Interned strings are not immortal; you must keep a reference to the return
  1443. value of <a class="reference internal" href="#sys.intern" title="sys.intern"><code class="xref py py-func docutils literal notranslate"><span class="pre">intern()</span></code></a> around to benefit from it.</p>
  1444. </dd></dl>
  1445. <dl class="py function">
  1446. <dt class="sig sig-object py" id="sys.is_finalizing">
  1447. <span class="sig-prename descclassname"><span class="pre">sys.</span></span><span class="sig-name descname"><span class="pre">is_finalizing</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#sys.is_finalizing" title="Link to this definition">¶</a></dt>
  1448. <dd><p>Return <a class="reference internal" href="constants.html#True" title="True"><code class="xref py py-const docutils literal notranslate"><span class="pre">True</span></code></a> if the Python interpreter is
  1449. <a class="reference internal" href="../glossary.html#term-interpreter-shutdown"><span class="xref std std-term">shutting down</span></a>, <a class="reference internal" href="constants.html#False" title="False"><code class="xref py py-const docutils literal notranslate"><span class="pre">False</span></code></a> otherwise.</p>
  1450. <div class="versionadded">
  1451. <p><span class="versionmodified added">New in version 3.5.</span></p>
  1452. </div>
  1453. </dd></dl>
  1454. <dl class="py data">
  1455. <dt class="sig sig-object py" id="sys.last_exc">
  1456. <span class="sig-prename descclassname"><span class="pre">sys.</span></span><span class="sig-name descname"><span class="pre">last_exc</span></span><a class="headerlink" href="#sys.last_exc" title="Link to this definition">¶</a></dt>
  1457. <dd><p>This variable is not always defined; it is set to the exception instance
  1458. when an exception is not handled and the interpreter prints an error message
  1459. and a stack traceback. Its intended use is to allow an interactive user to
  1460. import a debugger module and engage in post-mortem debugging without having
  1461. to re-execute the command that caused the error. (Typical use is
  1462. <code class="docutils literal notranslate"><span class="pre">import</span> <span class="pre">pdb;</span> <span class="pre">pdb.pm()</span></code> to enter the post-mortem debugger; see <a class="reference internal" href="pdb.html#module-pdb" title="pdb: The Python debugger for interactive interpreters."><code class="xref py py-mod docutils literal notranslate"><span class="pre">pdb</span></code></a>
  1463. module for more information.)</p>
  1464. <div class="versionadded">
  1465. <p><span class="versionmodified added">New in version 3.12.</span></p>
  1466. </div>
  1467. </dd></dl>
  1468. <dl class="py data">
  1469. <dt class="sig sig-object py" id="sys.last_type">
  1470. <span class="sig-prename descclassname"><span class="pre">sys.</span></span><span class="sig-name descname"><span class="pre">last_type</span></span><a class="headerlink" href="#sys.last_type" title="Link to this definition">¶</a></dt>
  1471. <dt class="sig sig-object py" id="sys.last_value">
  1472. <span class="sig-prename descclassname"><span class="pre">sys.</span></span><span class="sig-name descname"><span class="pre">last_value</span></span><a class="headerlink" href="#sys.last_value" title="Link to this definition">¶</a></dt>
  1473. <dt class="sig sig-object py" id="sys.last_traceback">
  1474. <span class="sig-prename descclassname"><span class="pre">sys.</span></span><span class="sig-name descname"><span class="pre">last_traceback</span></span><a class="headerlink" href="#sys.last_traceback" title="Link to this definition">¶</a></dt>
  1475. <dd><p>These three variables are deprecated; use <a class="reference internal" href="#sys.last_exc" title="sys.last_exc"><code class="xref py py-data docutils literal notranslate"><span class="pre">sys.last_exc</span></code></a> instead.
  1476. They hold the legacy representation of <code class="docutils literal notranslate"><span class="pre">sys.last_exc</span></code>, as returned
  1477. from <a class="reference internal" href="#sys.exc_info" title="sys.exc_info"><code class="xref py py-func docutils literal notranslate"><span class="pre">exc_info()</span></code></a> above.</p>
  1478. </dd></dl>
  1479. <dl class="py data">
  1480. <dt class="sig sig-object py" id="sys.maxsize">
  1481. <span class="sig-prename descclassname"><span class="pre">sys.</span></span><span class="sig-name descname"><span class="pre">maxsize</span></span><a class="headerlink" href="#sys.maxsize" title="Link to this definition">¶</a></dt>
  1482. <dd><p>An integer giving the maximum value a variable of type <a class="reference internal" href="../c-api/intro.html#c.Py_ssize_t" title="Py_ssize_t"><code class="xref c c-type docutils literal notranslate"><span class="pre">Py_ssize_t</span></code></a> can
  1483. take. It’s usually <code class="docutils literal notranslate"><span class="pre">2**31</span> <span class="pre">-</span> <span class="pre">1</span></code> on a 32-bit platform and <code class="docutils literal notranslate"><span class="pre">2**63</span> <span class="pre">-</span> <span class="pre">1</span></code> on a
  1484. 64-bit platform.</p>
  1485. </dd></dl>
  1486. <dl class="py data">
  1487. <dt class="sig sig-object py" id="sys.maxunicode">
  1488. <span class="sig-prename descclassname"><span class="pre">sys.</span></span><span class="sig-name descname"><span class="pre">maxunicode</span></span><a class="headerlink" href="#sys.maxunicode" title="Link to this definition">¶</a></dt>
  1489. <dd><p>An integer giving the value of the largest Unicode code point,
  1490. i.e. <code class="docutils literal notranslate"><span class="pre">1114111</span></code> (<code class="docutils literal notranslate"><span class="pre">0x10FFFF</span></code> in hexadecimal).</p>
  1491. <div class="versionchanged">
  1492. <p><span class="versionmodified changed">Changed in version 3.3: </span>Before <span class="target" id="index-19"></span><a class="pep reference external" href="https://peps.python.org/pep-0393/"><strong>PEP 393</strong></a>, <code class="docutils literal notranslate"><span class="pre">sys.maxunicode</span></code> used to be either <code class="docutils literal notranslate"><span class="pre">0xFFFF</span></code>
  1493. or <code class="docutils literal notranslate"><span class="pre">0x10FFFF</span></code>, depending on the configuration option that specified
  1494. whether Unicode characters were stored as UCS-2 or UCS-4.</p>
  1495. </div>
  1496. </dd></dl>
  1497. <dl class="py data">
  1498. <dt class="sig sig-object py" id="sys.meta_path">
  1499. <span class="sig-prename descclassname"><span class="pre">sys.</span></span><span class="sig-name descname"><span class="pre">meta_path</span></span><a class="headerlink" href="#sys.meta_path" title="Link to this definition">¶</a></dt>
  1500. <dd><p>A list of <a class="reference internal" href="../glossary.html#term-meta-path-finder"><span class="xref std std-term">meta path finder</span></a> objects that have their
  1501. <a class="reference internal" href="importlib.html#importlib.abc.MetaPathFinder.find_spec" title="importlib.abc.MetaPathFinder.find_spec"><code class="xref py py-meth docutils literal notranslate"><span class="pre">find_spec()</span></code></a> methods called to see if one
  1502. of the objects can find the module to be imported. By default, it holds entries
  1503. that implement Python’s default import semantics. The
  1504. <a class="reference internal" href="importlib.html#importlib.abc.MetaPathFinder.find_spec" title="importlib.abc.MetaPathFinder.find_spec"><code class="xref py py-meth docutils literal notranslate"><span class="pre">find_spec()</span></code></a> method is called with at
  1505. least the absolute name of the module being imported. If the module to be
  1506. imported is contained in a package, then the parent package’s <a class="reference internal" href="../reference/import.html#path__" title="__path__"><code class="xref py py-attr docutils literal notranslate"><span class="pre">__path__</span></code></a>
  1507. attribute is passed in as a second argument. The method returns a
  1508. <a class="reference internal" href="../glossary.html#term-module-spec"><span class="xref std std-term">module spec</span></a>, or <code class="docutils literal notranslate"><span class="pre">None</span></code> if the module cannot be found.</p>
  1509. <div class="admonition seealso">
  1510. <p class="admonition-title">See also</p>
  1511. <dl class="simple">
  1512. <dt><a class="reference internal" href="importlib.html#importlib.abc.MetaPathFinder" title="importlib.abc.MetaPathFinder"><code class="xref py py-class docutils literal notranslate"><span class="pre">importlib.abc.MetaPathFinder</span></code></a></dt><dd><p>The abstract base class defining the interface of finder objects on
  1513. <a class="reference internal" href="#sys.meta_path" title="sys.meta_path"><code class="xref py py-data docutils literal notranslate"><span class="pre">meta_path</span></code></a>.</p>
  1514. </dd>
  1515. <dt><a class="reference internal" href="importlib.html#importlib.machinery.ModuleSpec" title="importlib.machinery.ModuleSpec"><code class="xref py py-class docutils literal notranslate"><span class="pre">importlib.machinery.ModuleSpec</span></code></a></dt><dd><p>The concrete class which
  1516. <a class="reference internal" href="importlib.html#importlib.abc.MetaPathFinder.find_spec" title="importlib.abc.MetaPathFinder.find_spec"><code class="xref py py-meth docutils literal notranslate"><span class="pre">find_spec()</span></code></a> should return
  1517. instances of.</p>
  1518. </dd>
  1519. </dl>
  1520. </div>
  1521. <div class="versionchanged">
  1522. <p><span class="versionmodified changed">Changed in version 3.4: </span><a class="reference internal" href="../glossary.html#term-module-spec"><span class="xref std std-term">Module specs</span></a> were introduced in Python 3.4, by
  1523. <span class="target" id="index-20"></span><a class="pep reference external" href="https://peps.python.org/pep-0451/"><strong>PEP 451</strong></a>.</p>
  1524. </div>
  1525. <div class="versionchanged">
  1526. <p><span class="versionmodified changed">Changed in version 3.12: </span>Removed the fallback that looked for a <code class="xref py py-meth docutils literal notranslate"><span class="pre">find_module()</span></code> method
  1527. if a <a class="reference internal" href="#sys.meta_path" title="sys.meta_path"><code class="xref py py-data docutils literal notranslate"><span class="pre">meta_path</span></code></a> entry didn’t have a
  1528. <a class="reference internal" href="importlib.html#importlib.abc.MetaPathFinder.find_spec" title="importlib.abc.MetaPathFinder.find_spec"><code class="xref py py-meth docutils literal notranslate"><span class="pre">find_spec()</span></code></a> method.</p>
  1529. </div>
  1530. </dd></dl>
  1531. <dl class="py data">
  1532. <dt class="sig sig-object py" id="sys.modules">
  1533. <span class="sig-prename descclassname"><span class="pre">sys.</span></span><span class="sig-name descname"><span class="pre">modules</span></span><a class="headerlink" href="#sys.modules" title="Link to this definition">¶</a></dt>
  1534. <dd><p>This is a dictionary that maps module names to modules which have already been
  1535. loaded. This can be manipulated to force reloading of modules and other tricks.
  1536. However, replacing the dictionary will not necessarily work as expected and
  1537. deleting essential items from the dictionary may cause Python to fail. If
  1538. you want to iterate over this global dictionary always use
  1539. <code class="docutils literal notranslate"><span class="pre">sys.modules.copy()</span></code> or <code class="docutils literal notranslate"><span class="pre">tuple(sys.modules)</span></code> to avoid exceptions as its
  1540. size may change during iteration as a side effect of code or activity in
  1541. other threads.</p>
  1542. </dd></dl>
  1543. <dl class="py data">
  1544. <dt class="sig sig-object py" id="sys.orig_argv">
  1545. <span class="sig-prename descclassname"><span class="pre">sys.</span></span><span class="sig-name descname"><span class="pre">orig_argv</span></span><a class="headerlink" href="#sys.orig_argv" title="Link to this definition">¶</a></dt>
  1546. <dd><p>The list of the original command line arguments passed to the Python
  1547. executable.</p>
  1548. <p>The elements of <a class="reference internal" href="#sys.orig_argv" title="sys.orig_argv"><code class="xref py py-data docutils literal notranslate"><span class="pre">sys.orig_argv</span></code></a> are the arguments to the Python interpreter,
  1549. while the elements of <a class="reference internal" href="#sys.argv" title="sys.argv"><code class="xref py py-data docutils literal notranslate"><span class="pre">sys.argv</span></code></a> are the arguments to the user’s program.
  1550. Arguments consumed by the interpreter itself will be present in <a class="reference internal" href="#sys.orig_argv" title="sys.orig_argv"><code class="xref py py-data docutils literal notranslate"><span class="pre">sys.orig_argv</span></code></a>
  1551. and missing from <a class="reference internal" href="#sys.argv" title="sys.argv"><code class="xref py py-data docutils literal notranslate"><span class="pre">sys.argv</span></code></a>.</p>
  1552. <div class="versionadded">
  1553. <p><span class="versionmodified added">New in version 3.10.</span></p>
  1554. </div>
  1555. </dd></dl>
  1556. <dl class="py data">
  1557. <dt class="sig sig-object py" id="sys.path">
  1558. <span class="sig-prename descclassname"><span class="pre">sys.</span></span><span class="sig-name descname"><span class="pre">path</span></span><a class="headerlink" href="#sys.path" title="Link to this definition">¶</a></dt>
  1559. <dd><p id="index-21">A list of strings that specifies the search path for modules. Initialized from
  1560. the environment variable <span class="target" id="index-22"></span><a class="reference internal" href="../using/cmdline.html#envvar-PYTHONPATH"><code class="xref std std-envvar docutils literal notranslate"><span class="pre">PYTHONPATH</span></code></a>, plus an installation-dependent
  1561. default.</p>
  1562. <p>By default, as initialized upon program startup, a potentially unsafe path
  1563. is prepended to <a class="reference internal" href="#sys.path" title="sys.path"><code class="xref py py-data docutils literal notranslate"><span class="pre">sys.path</span></code></a> (<em>before</em> the entries inserted as a result
  1564. of <span class="target" id="index-23"></span><a class="reference internal" href="../using/cmdline.html#envvar-PYTHONPATH"><code class="xref std std-envvar docutils literal notranslate"><span class="pre">PYTHONPATH</span></code></a>):</p>
  1565. <ul class="simple">
  1566. <li><p><code class="docutils literal notranslate"><span class="pre">python</span> <span class="pre">-m</span> <span class="pre">module</span></code> command line: prepend the current working
  1567. directory.</p></li>
  1568. <li><p><code class="docutils literal notranslate"><span class="pre">python</span> <span class="pre">script.py</span></code> command line: prepend the script’s directory.
  1569. If it’s a symbolic link, resolve symbolic links.</p></li>
  1570. <li><p><code class="docutils literal notranslate"><span class="pre">python</span> <span class="pre">-c</span> <span class="pre">code</span></code> and <code class="docutils literal notranslate"><span class="pre">python</span></code> (REPL) command lines: prepend an empty
  1571. string, which means the current working directory.</p></li>
  1572. </ul>
  1573. <p>To not prepend this potentially unsafe path, use the <a class="reference internal" href="../using/cmdline.html#cmdoption-P"><code class="xref std std-option docutils literal notranslate"><span class="pre">-P</span></code></a> command
  1574. line option or the <span class="target" id="index-24"></span><a class="reference internal" href="../using/cmdline.html#envvar-PYTHONSAFEPATH"><code class="xref std std-envvar docutils literal notranslate"><span class="pre">PYTHONSAFEPATH</span></code></a> environment variable.</p>
  1575. <p>A program is free to modify this list for its own purposes. Only strings
  1576. should be added to <a class="reference internal" href="#sys.path" title="sys.path"><code class="xref py py-data docutils literal notranslate"><span class="pre">sys.path</span></code></a>; all other data types are
  1577. ignored during import.</p>
  1578. <div class="admonition seealso">
  1579. <p class="admonition-title">See also</p>
  1580. <ul class="simple">
  1581. <li><p>Module <a class="reference internal" href="site.html#module-site" title="site: Module responsible for site-specific configuration."><code class="xref py py-mod docutils literal notranslate"><span class="pre">site</span></code></a> This describes how to use .pth files to
  1582. extend <a class="reference internal" href="#sys.path" title="sys.path"><code class="xref py py-data docutils literal notranslate"><span class="pre">sys.path</span></code></a>.</p></li>
  1583. </ul>
  1584. </div>
  1585. </dd></dl>
  1586. <dl class="py data">
  1587. <dt class="sig sig-object py" id="sys.path_hooks">
  1588. <span class="sig-prename descclassname"><span class="pre">sys.</span></span><span class="sig-name descname"><span class="pre">path_hooks</span></span><a class="headerlink" href="#sys.path_hooks" title="Link to this definition">¶</a></dt>
  1589. <dd><p>A list of callables that take a path argument to try to create a
  1590. <a class="reference internal" href="../glossary.html#term-finder"><span class="xref std std-term">finder</span></a> for the path. If a finder can be created, it is to be
  1591. returned by the callable, else raise <a class="reference internal" href="exceptions.html#ImportError" title="ImportError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">ImportError</span></code></a>.</p>
  1592. <p>Originally specified in <span class="target" id="index-25"></span><a class="pep reference external" href="https://peps.python.org/pep-0302/"><strong>PEP 302</strong></a>.</p>
  1593. </dd></dl>
  1594. <dl class="py data">
  1595. <dt class="sig sig-object py" id="sys.path_importer_cache">
  1596. <span class="sig-prename descclassname"><span class="pre">sys.</span></span><span class="sig-name descname"><span class="pre">path_importer_cache</span></span><a class="headerlink" href="#sys.path_importer_cache" title="Link to this definition">¶</a></dt>
  1597. <dd><p>A dictionary acting as a cache for <a class="reference internal" href="../glossary.html#term-finder"><span class="xref std std-term">finder</span></a> objects. The keys are
  1598. paths that have been passed to <a class="reference internal" href="#sys.path_hooks" title="sys.path_hooks"><code class="xref py py-data docutils literal notranslate"><span class="pre">sys.path_hooks</span></code></a> and the values are
  1599. the finders that are found. If a path is a valid file system path but no
  1600. finder is found on <a class="reference internal" href="#sys.path_hooks" title="sys.path_hooks"><code class="xref py py-data docutils literal notranslate"><span class="pre">sys.path_hooks</span></code></a> then <code class="docutils literal notranslate"><span class="pre">None</span></code> is
  1601. stored.</p>
  1602. <p>Originally specified in <span class="target" id="index-26"></span><a class="pep reference external" href="https://peps.python.org/pep-0302/"><strong>PEP 302</strong></a>.</p>
  1603. </dd></dl>
  1604. <dl class="py data">
  1605. <dt class="sig sig-object py" id="sys.platform">
  1606. <span class="sig-prename descclassname"><span class="pre">sys.</span></span><span class="sig-name descname"><span class="pre">platform</span></span><a class="headerlink" href="#sys.platform" title="Link to this definition">¶</a></dt>
  1607. <dd><p>This string contains a platform identifier that can be used to append
  1608. platform-specific components to <a class="reference internal" href="#sys.path" title="sys.path"><code class="xref py py-data docutils literal notranslate"><span class="pre">sys.path</span></code></a>, for instance.</p>
  1609. <p>For Unix systems, except on Linux and AIX, this is the lowercased OS name as
  1610. returned by <code class="docutils literal notranslate"><span class="pre">uname</span> <span class="pre">-s</span></code> with the first part of the version as returned by
  1611. <code class="docutils literal notranslate"><span class="pre">uname</span> <span class="pre">-r</span></code> appended, e.g. <code class="docutils literal notranslate"><span class="pre">'sunos5'</span></code> or <code class="docutils literal notranslate"><span class="pre">'freebsd8'</span></code>, <em>at the time
  1612. when Python was built</em>. Unless you want to test for a specific system
  1613. version, it is therefore recommended to use the following idiom:</p>
  1614. <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="k">if</span> <span class="n">sys</span><span class="o">.</span><span class="n">platform</span><span class="o">.</span><span class="n">startswith</span><span class="p">(</span><span class="s1">&#39;freebsd&#39;</span><span class="p">):</span>
  1615. <span class="c1"># FreeBSD-specific code here...</span>
  1616. <span class="k">elif</span> <span class="n">sys</span><span class="o">.</span><span class="n">platform</span><span class="o">.</span><span class="n">startswith</span><span class="p">(</span><span class="s1">&#39;linux&#39;</span><span class="p">):</span>
  1617. <span class="c1"># Linux-specific code here...</span>
  1618. <span class="k">elif</span> <span class="n">sys</span><span class="o">.</span><span class="n">platform</span><span class="o">.</span><span class="n">startswith</span><span class="p">(</span><span class="s1">&#39;aix&#39;</span><span class="p">):</span>
  1619. <span class="c1"># AIX-specific code here...</span>
  1620. </pre></div>
  1621. </div>
  1622. <p>For other systems, the values are:</p>
  1623. <table class="docutils align-default">
  1624. <thead>
  1625. <tr class="row-odd"><th class="head"><p>System</p></th>
  1626. <th class="head"><p><code class="docutils literal notranslate"><span class="pre">platform</span></code> value</p></th>
  1627. </tr>
  1628. </thead>
  1629. <tbody>
  1630. <tr class="row-even"><td><p>AIX</p></td>
  1631. <td><p><code class="docutils literal notranslate"><span class="pre">'aix'</span></code></p></td>
  1632. </tr>
  1633. <tr class="row-odd"><td><p>Emscripten</p></td>
  1634. <td><p><code class="docutils literal notranslate"><span class="pre">'emscripten'</span></code></p></td>
  1635. </tr>
  1636. <tr class="row-even"><td><p>Linux</p></td>
  1637. <td><p><code class="docutils literal notranslate"><span class="pre">'linux'</span></code></p></td>
  1638. </tr>
  1639. <tr class="row-odd"><td><p>WASI</p></td>
  1640. <td><p><code class="docutils literal notranslate"><span class="pre">'wasi'</span></code></p></td>
  1641. </tr>
  1642. <tr class="row-even"><td><p>Windows</p></td>
  1643. <td><p><code class="docutils literal notranslate"><span class="pre">'win32'</span></code></p></td>
  1644. </tr>
  1645. <tr class="row-odd"><td><p>Windows/Cygwin</p></td>
  1646. <td><p><code class="docutils literal notranslate"><span class="pre">'cygwin'</span></code></p></td>
  1647. </tr>
  1648. <tr class="row-even"><td><p>macOS</p></td>
  1649. <td><p><code class="docutils literal notranslate"><span class="pre">'darwin'</span></code></p></td>
  1650. </tr>
  1651. </tbody>
  1652. </table>
  1653. <div class="versionchanged">
  1654. <p><span class="versionmodified changed">Changed in version 3.3: </span>On Linux, <a class="reference internal" href="#sys.platform" title="sys.platform"><code class="xref py py-data docutils literal notranslate"><span class="pre">sys.platform</span></code></a> doesn’t contain the major version anymore.
  1655. It is always <code class="docutils literal notranslate"><span class="pre">'linux'</span></code>, instead of <code class="docutils literal notranslate"><span class="pre">'linux2'</span></code> or <code class="docutils literal notranslate"><span class="pre">'linux3'</span></code>. Since
  1656. older Python versions include the version number, it is recommended to
  1657. always use the <code class="docutils literal notranslate"><span class="pre">startswith</span></code> idiom presented above.</p>
  1658. </div>
  1659. <div class="versionchanged">
  1660. <p><span class="versionmodified changed">Changed in version 3.8: </span>On AIX, <a class="reference internal" href="#sys.platform" title="sys.platform"><code class="xref py py-data docutils literal notranslate"><span class="pre">sys.platform</span></code></a> doesn’t contain the major version anymore.
  1661. It is always <code class="docutils literal notranslate"><span class="pre">'aix'</span></code>, instead of <code class="docutils literal notranslate"><span class="pre">'aix5'</span></code> or <code class="docutils literal notranslate"><span class="pre">'aix7'</span></code>. Since
  1662. older Python versions include the version number, it is recommended to
  1663. always use the <code class="docutils literal notranslate"><span class="pre">startswith</span></code> idiom presented above.</p>
  1664. </div>
  1665. <div class="admonition seealso">
  1666. <p class="admonition-title">See also</p>
  1667. <p><a class="reference internal" href="os.html#os.name" title="os.name"><code class="xref py py-data docutils literal notranslate"><span class="pre">os.name</span></code></a> has a coarser granularity. <a class="reference internal" href="os.html#os.uname" title="os.uname"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.uname()</span></code></a> gives
  1668. system-dependent version information.</p>
  1669. <p>The <a class="reference internal" href="platform.html#module-platform" title="platform: Retrieves as much platform identifying data as possible."><code class="xref py py-mod docutils literal notranslate"><span class="pre">platform</span></code></a> module provides detailed checks for the
  1670. system’s identity.</p>
  1671. </div>
  1672. </dd></dl>
  1673. <dl class="py data">
  1674. <dt class="sig sig-object py" id="sys.platlibdir">
  1675. <span class="sig-prename descclassname"><span class="pre">sys.</span></span><span class="sig-name descname"><span class="pre">platlibdir</span></span><a class="headerlink" href="#sys.platlibdir" title="Link to this definition">¶</a></dt>
  1676. <dd><p>Name of the platform-specific library directory. It is used to build the
  1677. path of standard library and the paths of installed extension modules.</p>
  1678. <p>It is equal to <code class="docutils literal notranslate"><span class="pre">&quot;lib&quot;</span></code> on most platforms. On Fedora and SuSE, it is equal
  1679. to <code class="docutils literal notranslate"><span class="pre">&quot;lib64&quot;</span></code> on 64-bit platforms which gives the following <code class="docutils literal notranslate"><span class="pre">sys.path</span></code>
  1680. paths (where <code class="docutils literal notranslate"><span class="pre">X.Y</span></code> is the Python <code class="docutils literal notranslate"><span class="pre">major.minor</span></code> version):</p>
  1681. <ul class="simple">
  1682. <li><p><code class="docutils literal notranslate"><span class="pre">/usr/lib64/pythonX.Y/</span></code>:
  1683. Standard library (like <code class="docutils literal notranslate"><span class="pre">os.py</span></code> of the <a class="reference internal" href="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)</p></li>
  1684. <li><p><code class="docutils literal notranslate"><span class="pre">/usr/lib64/pythonX.Y/lib-dynload/</span></code>:
  1685. C extension modules of the standard library (like the <a class="reference internal" href="errno.html#module-errno" title="errno: Standard errno system symbols."><code class="xref py py-mod docutils literal notranslate"><span class="pre">errno</span></code></a> module,
  1686. the exact filename is platform specific)</p></li>
  1687. <li><p><code class="docutils literal notranslate"><span class="pre">/usr/lib/pythonX.Y/site-packages/</span></code> (always use <code class="docutils literal notranslate"><span class="pre">lib</span></code>, not
  1688. <a class="reference internal" href="#sys.platlibdir" title="sys.platlibdir"><code class="xref py py-data docutils literal notranslate"><span class="pre">sys.platlibdir</span></code></a>): Third-party modules</p></li>
  1689. <li><p><code class="docutils literal notranslate"><span class="pre">/usr/lib64/pythonX.Y/site-packages/</span></code>:
  1690. C extension modules of third-party packages</p></li>
  1691. </ul>
  1692. <div class="versionadded">
  1693. <p><span class="versionmodified added">New in version 3.9.</span></p>
  1694. </div>
  1695. </dd></dl>
  1696. <dl class="py data">
  1697. <dt class="sig sig-object py" id="sys.prefix">
  1698. <span class="sig-prename descclassname"><span class="pre">sys.</span></span><span class="sig-name descname"><span class="pre">prefix</span></span><a class="headerlink" href="#sys.prefix" title="Link to this definition">¶</a></dt>
  1699. <dd><p>A string giving the site-specific directory prefix where the platform
  1700. independent Python files are installed; on Unix, the default is
  1701. <code class="file docutils literal notranslate"><span class="pre">/usr/local</span></code>. This can be set at build time with the <a class="reference internal" href="../using/configure.html#cmdoption-prefix"><code class="xref std std-option docutils literal notranslate"><span class="pre">--prefix</span></code></a>
  1702. argument to the <strong class="program">configure</strong> script. See
  1703. <a class="reference internal" href="sysconfig.html#installation-paths"><span class="std std-ref">Installation paths</span></a> for derived paths.</p>
  1704. <div class="admonition note">
  1705. <p class="admonition-title">Note</p>
  1706. <p>If a <a class="reference internal" href="venv.html#venv-def"><span class="std std-ref">virtual environment</span></a> is in effect, this
  1707. value will be changed in <code class="docutils literal notranslate"><span class="pre">site.py</span></code> to point to the virtual
  1708. environment. The value for the Python installation will still be
  1709. available, via <a class="reference internal" href="#sys.base_prefix" title="sys.base_prefix"><code class="xref py py-data docutils literal notranslate"><span class="pre">base_prefix</span></code></a>.</p>
  1710. </div>
  1711. </dd></dl>
  1712. <dl class="py data">
  1713. <dt class="sig sig-object py" id="sys.ps1">
  1714. <span class="sig-prename descclassname"><span class="pre">sys.</span></span><span class="sig-name descname"><span class="pre">ps1</span></span><a class="headerlink" href="#sys.ps1" title="Link to this definition">¶</a></dt>
  1715. <dt class="sig sig-object py" id="sys.ps2">
  1716. <span class="sig-prename descclassname"><span class="pre">sys.</span></span><span class="sig-name descname"><span class="pre">ps2</span></span><a class="headerlink" href="#sys.ps2" title="Link to this definition">¶</a></dt>
  1717. <dd><p id="index-27">Strings specifying the primary and secondary prompt of the interpreter. These
  1718. are only defined if the interpreter is in interactive mode. Their initial
  1719. values in this case are <code class="docutils literal notranslate"><span class="pre">'&gt;&gt;&gt;</span> <span class="pre">'</span></code> and <code class="docutils literal notranslate"><span class="pre">'...</span> <span class="pre">'</span></code>. If a non-string object is
  1720. assigned to either variable, its <a class="reference internal" href="stdtypes.html#str" title="str"><code class="xref py py-func docutils literal notranslate"><span class="pre">str()</span></code></a> is re-evaluated each time the
  1721. interpreter prepares to read a new interactive command; this can be used to
  1722. implement a dynamic prompt.</p>
  1723. </dd></dl>
  1724. <dl class="py function">
  1725. <dt class="sig sig-object py" id="sys.setdlopenflags">
  1726. <span class="sig-prename descclassname"><span class="pre">sys.</span></span><span class="sig-name descname"><span class="pre">setdlopenflags</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">n</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#sys.setdlopenflags" title="Link to this definition">¶</a></dt>
  1727. <dd><p>Set the flags used by the interpreter for <code class="xref c c-func docutils literal notranslate"><span class="pre">dlopen()</span></code> calls, such as when
  1728. the interpreter loads extension modules. Among other things, this will enable a
  1729. lazy resolving of symbols when importing a module, if called as
  1730. <code class="docutils literal notranslate"><span class="pre">sys.setdlopenflags(0)</span></code>. To share symbols across extension modules, call as
  1731. <code class="docutils literal notranslate"><span class="pre">sys.setdlopenflags(os.RTLD_GLOBAL)</span></code>. Symbolic names for the flag values
  1732. can be found in the <a class="reference internal" href="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 (<code class="samp docutils literal notranslate"><span class="pre">RTLD_</span><em><span class="pre">xxx</span></em></code> constants, e.g.
  1733. <a class="reference internal" href="os.html#os.RTLD_LAZY" title="os.RTLD_LAZY"><code class="xref py py-const docutils literal notranslate"><span class="pre">os.RTLD_LAZY</span></code></a>).</p>
  1734. <div class="availability docutils container">
  1735. <p><a class="reference internal" href="intro.html#availability"><span class="std std-ref">Availability</span></a>: Unix.</p>
  1736. </div>
  1737. </dd></dl>
  1738. <dl class="py function">
  1739. <dt class="sig sig-object py" id="sys.set_int_max_str_digits">
  1740. <span class="sig-prename descclassname"><span class="pre">sys.</span></span><span class="sig-name descname"><span class="pre">set_int_max_str_digits</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">maxdigits</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#sys.set_int_max_str_digits" title="Link to this definition">¶</a></dt>
  1741. <dd><p>Set the <a class="reference internal" href="stdtypes.html#int-max-str-digits"><span class="std std-ref">integer string conversion length limitation</span></a> used by this interpreter. See also
  1742. <a class="reference internal" href="#sys.get_int_max_str_digits" title="sys.get_int_max_str_digits"><code class="xref py py-func docutils literal notranslate"><span class="pre">get_int_max_str_digits()</span></code></a>.</p>
  1743. <div class="versionadded">
  1744. <p><span class="versionmodified added">New in version 3.11.</span></p>
  1745. </div>
  1746. </dd></dl>
  1747. <dl class="py function">
  1748. <dt class="sig sig-object py" id="sys.setprofile">
  1749. <span class="sig-prename descclassname"><span class="pre">sys.</span></span><span class="sig-name descname"><span class="pre">setprofile</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">profilefunc</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#sys.setprofile" title="Link to this definition">¶</a></dt>
  1750. <dd><p id="index-28">Set the system’s profile function, which allows you to implement a Python source
  1751. code profiler in Python. See chapter <a class="reference internal" href="profile.html#profile"><span class="std std-ref">The Python Profilers</span></a> for more information on the
  1752. Python profiler. The system’s profile function is called similarly to the
  1753. system’s trace function (see <a class="reference internal" href="#sys.settrace" title="sys.settrace"><code class="xref py py-func docutils literal notranslate"><span class="pre">settrace()</span></code></a>), but it is called with different events,
  1754. for example it isn’t called for each executed line of code (only on call and return,
  1755. but the return event is reported even when an exception has been set). The function is
  1756. thread-specific, but there is no way for the profiler to know about context switches between
  1757. threads, so it does not make sense to use this in the presence of multiple threads. Also,
  1758. its return value is not used, so it can simply return <code class="docutils literal notranslate"><span class="pre">None</span></code>. Error in the profile
  1759. function will cause itself unset.</p>
  1760. <div class="admonition note">
  1761. <p class="admonition-title">Note</p>
  1762. <p>The same tracing mechanism is used for <code class="xref py py-func docutils literal notranslate"><span class="pre">setprofile()</span></code> as <a class="reference internal" href="#sys.settrace" title="sys.settrace"><code class="xref py py-func docutils literal notranslate"><span class="pre">settrace()</span></code></a>.
  1763. To trace calls with <code class="xref py py-func docutils literal notranslate"><span class="pre">setprofile()</span></code> inside a tracing function
  1764. (e.g. in a debugger breakpoint), see <a class="reference internal" href="#sys.call_tracing" title="sys.call_tracing"><code class="xref py py-func docutils literal notranslate"><span class="pre">call_tracing()</span></code></a>.</p>
  1765. </div>
  1766. <p>Profile functions should have three arguments: <em>frame</em>, <em>event</em>, and
  1767. <em>arg</em>. <em>frame</em> is the current stack frame. <em>event</em> is a string: <code class="docutils literal notranslate"><span class="pre">'call'</span></code>,
  1768. <code class="docutils literal notranslate"><span class="pre">'return'</span></code>, <code class="docutils literal notranslate"><span class="pre">'c_call'</span></code>, <code class="docutils literal notranslate"><span class="pre">'c_return'</span></code>, or <code class="docutils literal notranslate"><span class="pre">'c_exception'</span></code>. <em>arg</em> depends
  1769. on the event type.</p>
  1770. <p>The events have the following meaning:</p>
  1771. <dl class="simple">
  1772. <dt><code class="docutils literal notranslate"><span class="pre">'call'</span></code></dt><dd><p>A function is called (or some other code block entered). The
  1773. profile function is called; <em>arg</em> is <code class="docutils literal notranslate"><span class="pre">None</span></code>.</p>
  1774. </dd>
  1775. <dt><code class="docutils literal notranslate"><span class="pre">'return'</span></code></dt><dd><p>A function (or other code block) is about to return. The profile
  1776. function is called; <em>arg</em> is the value that will be returned, or <code class="docutils literal notranslate"><span class="pre">None</span></code>
  1777. if the event is caused by an exception being raised.</p>
  1778. </dd>
  1779. <dt><code class="docutils literal notranslate"><span class="pre">'c_call'</span></code></dt><dd><p>A C function is about to be called. This may be an extension function or
  1780. a built-in. <em>arg</em> is the C function object.</p>
  1781. </dd>
  1782. <dt><code class="docutils literal notranslate"><span class="pre">'c_return'</span></code></dt><dd><p>A C function has returned. <em>arg</em> is the C function object.</p>
  1783. </dd>
  1784. <dt><code class="docutils literal notranslate"><span class="pre">'c_exception'</span></code></dt><dd><p>A C function has raised an exception. <em>arg</em> is the C function object.</p>
  1785. </dd>
  1786. </dl>
  1787. <p class="audit-hook">Raises an <a class="reference internal" href="#auditing"><span class="std std-ref">auditing event</span></a> <code class="docutils literal notranslate"><span class="pre">sys.setprofile</span></code> with no arguments.</p>
  1788. </dd></dl>
  1789. <dl class="py function">
  1790. <dt class="sig sig-object py" id="sys.setrecursionlimit">
  1791. <span class="sig-prename descclassname"><span class="pre">sys.</span></span><span class="sig-name descname"><span class="pre">setrecursionlimit</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">limit</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#sys.setrecursionlimit" title="Link to this definition">¶</a></dt>
  1792. <dd><p>Set the maximum depth of the Python interpreter stack to <em>limit</em>. This limit
  1793. prevents infinite recursion from causing an overflow of the C stack and crashing
  1794. Python.</p>
  1795. <p>The highest possible limit is platform-dependent. A user may need to set the
  1796. limit higher when they have a program that requires deep recursion and a platform
  1797. that supports a higher limit. This should be done with care, because a too-high
  1798. limit can lead to a crash.</p>
  1799. <p>If the new limit is too low at the current recursion depth, a
  1800. <a class="reference internal" href="exceptions.html#RecursionError" title="RecursionError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">RecursionError</span></code></a> exception is raised.</p>
  1801. <div class="versionchanged">
  1802. <p><span class="versionmodified changed">Changed in version 3.5.1: </span>A <a class="reference internal" href="exceptions.html#RecursionError" title="RecursionError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">RecursionError</span></code></a> exception is now raised if the new limit is too
  1803. low at the current recursion depth.</p>
  1804. </div>
  1805. </dd></dl>
  1806. <dl class="py function">
  1807. <dt class="sig sig-object py" id="sys.setswitchinterval">
  1808. <span class="sig-prename descclassname"><span class="pre">sys.</span></span><span class="sig-name descname"><span class="pre">setswitchinterval</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">interval</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#sys.setswitchinterval" title="Link to this definition">¶</a></dt>
  1809. <dd><p>Set the interpreter’s thread switch interval (in seconds). This floating-point
  1810. value determines the ideal duration of the “timeslices” allocated to
  1811. concurrently running Python threads. Please note that the actual value
  1812. can be higher, especially if long-running internal functions or methods
  1813. are used. Also, which thread becomes scheduled at the end of the interval
  1814. is the operating system’s decision. The interpreter doesn’t have its
  1815. own scheduler.</p>
  1816. <div class="versionadded">
  1817. <p><span class="versionmodified added">New in version 3.2.</span></p>
  1818. </div>
  1819. </dd></dl>
  1820. <dl class="py function">
  1821. <dt class="sig sig-object py" id="sys.settrace">
  1822. <span class="sig-prename descclassname"><span class="pre">sys.</span></span><span class="sig-name descname"><span class="pre">settrace</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">tracefunc</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#sys.settrace" title="Link to this definition">¶</a></dt>
  1823. <dd><p id="index-29">Set the system’s trace function, which allows you to implement a Python
  1824. source code debugger in Python. The function is thread-specific; for a
  1825. debugger to support multiple threads, it must register a trace function using
  1826. <a class="reference internal" href="#sys.settrace" title="sys.settrace"><code class="xref py py-func docutils literal notranslate"><span class="pre">settrace()</span></code></a> for each thread being debugged or use <a class="reference internal" href="threading.html#threading.settrace" title="threading.settrace"><code class="xref py py-func docutils literal notranslate"><span class="pre">threading.settrace()</span></code></a>.</p>
  1827. <p>Trace functions should have three arguments: <em>frame</em>, <em>event</em>, and
  1828. <em>arg</em>. <em>frame</em> is the current stack frame. <em>event</em> is a string: <code class="docutils literal notranslate"><span class="pre">'call'</span></code>,
  1829. <code class="docutils literal notranslate"><span class="pre">'line'</span></code>, <code class="docutils literal notranslate"><span class="pre">'return'</span></code>, <code class="docutils literal notranslate"><span class="pre">'exception'</span></code> or <code class="docutils literal notranslate"><span class="pre">'opcode'</span></code>. <em>arg</em> depends on
  1830. the event type.</p>
  1831. <p>The trace function is invoked (with <em>event</em> set to <code class="docutils literal notranslate"><span class="pre">'call'</span></code>) whenever a new
  1832. local scope is entered; it should return a reference to a local trace
  1833. function to be used for the new scope, or <code class="docutils literal notranslate"><span class="pre">None</span></code> if the scope shouldn’t be
  1834. traced.</p>
  1835. <p>The local trace function should return a reference to itself, or to another
  1836. function which would then be used as the local trace function for the scope.</p>
  1837. <p>If there is any error occurred in the trace function, it will be unset, just
  1838. like <code class="docutils literal notranslate"><span class="pre">settrace(None)</span></code> is called.</p>
  1839. <div class="admonition note">
  1840. <p class="admonition-title">Note</p>
  1841. <p>Tracing is disabled while calling the trace function (e.g. a function set by
  1842. <code class="xref py py-func docutils literal notranslate"><span class="pre">settrace()</span></code>). For recursive tracing see <a class="reference internal" href="#sys.call_tracing" title="sys.call_tracing"><code class="xref py py-func docutils literal notranslate"><span class="pre">call_tracing()</span></code></a>.</p>
  1843. </div>
  1844. <p>The events have the following meaning:</p>
  1845. <dl class="simple">
  1846. <dt><code class="docutils literal notranslate"><span class="pre">'call'</span></code></dt><dd><p>A function is called (or some other code block entered). The
  1847. global trace function is called; <em>arg</em> is <code class="docutils literal notranslate"><span class="pre">None</span></code>; the return value
  1848. specifies the local trace function.</p>
  1849. </dd>
  1850. <dt><code class="docutils literal notranslate"><span class="pre">'line'</span></code></dt><dd><p>The interpreter is about to execute a new line of code or re-execute the
  1851. condition of a loop. The local trace function is called; <em>arg</em> is
  1852. <code class="docutils literal notranslate"><span class="pre">None</span></code>; the return value specifies the new local trace function. See
  1853. <code class="file docutils literal notranslate"><span class="pre">Objects/lnotab_notes.txt</span></code> for a detailed explanation of how this
  1854. works.
  1855. Per-line events may be disabled for a frame by setting
  1856. <a class="reference internal" href="../reference/datamodel.html#frame.f_trace_lines" title="frame.f_trace_lines"><code class="xref py py-attr docutils literal notranslate"><span class="pre">f_trace_lines</span></code></a> to <a class="reference internal" href="constants.html#False" title="False"><code class="xref py py-const docutils literal notranslate"><span class="pre">False</span></code></a> on that
  1857. <a class="reference internal" href="../reference/datamodel.html#frame-objects"><span class="std std-ref">frame</span></a>.</p>
  1858. </dd>
  1859. <dt><code class="docutils literal notranslate"><span class="pre">'return'</span></code></dt><dd><p>A function (or other code block) is about to return. The local trace
  1860. function is called; <em>arg</em> is the value that will be returned, or <code class="docutils literal notranslate"><span class="pre">None</span></code>
  1861. if the event is caused by an exception being raised. The trace function’s
  1862. return value is ignored.</p>
  1863. </dd>
  1864. <dt><code class="docutils literal notranslate"><span class="pre">'exception'</span></code></dt><dd><p>An exception has occurred. The local trace function is called; <em>arg</em> is a
  1865. tuple <code class="docutils literal notranslate"><span class="pre">(exception,</span> <span class="pre">value,</span> <span class="pre">traceback)</span></code>; the return value specifies the
  1866. new local trace function.</p>
  1867. </dd>
  1868. <dt><code class="docutils literal notranslate"><span class="pre">'opcode'</span></code></dt><dd><p>The interpreter is about to execute a new opcode (see <a class="reference internal" href="dis.html#module-dis" title="dis: Disassembler for Python bytecode."><code class="xref py py-mod docutils literal notranslate"><span class="pre">dis</span></code></a> for
  1869. opcode details). The local trace function is called; <em>arg</em> is
  1870. <code class="docutils literal notranslate"><span class="pre">None</span></code>; the return value specifies the new local trace function.
  1871. Per-opcode events are not emitted by default: they must be explicitly
  1872. requested by setting <a class="reference internal" href="../reference/datamodel.html#frame.f_trace_opcodes" title="frame.f_trace_opcodes"><code class="xref py py-attr docutils literal notranslate"><span class="pre">f_trace_opcodes</span></code></a> to <a class="reference internal" href="constants.html#True" title="True"><code class="xref py py-const docutils literal notranslate"><span class="pre">True</span></code></a> on the
  1873. <a class="reference internal" href="../reference/datamodel.html#frame-objects"><span class="std std-ref">frame</span></a>.</p>
  1874. </dd>
  1875. </dl>
  1876. <p>Note that as an exception is propagated down the chain of callers, an
  1877. <code class="docutils literal notranslate"><span class="pre">'exception'</span></code> event is generated at each level.</p>
  1878. <p>For more fine-grained usage, it’s possible to set a trace function by
  1879. assigning <code class="docutils literal notranslate"><span class="pre">frame.f_trace</span> <span class="pre">=</span> <span class="pre">tracefunc</span></code> explicitly, rather than relying on
  1880. it being set indirectly via the return value from an already installed
  1881. trace function. This is also required for activating the trace function on
  1882. the current frame, which <a class="reference internal" href="#sys.settrace" title="sys.settrace"><code class="xref py py-func docutils literal notranslate"><span class="pre">settrace()</span></code></a> doesn’t do. Note that in order
  1883. for this to work, a global tracing function must have been installed
  1884. with <a class="reference internal" href="#sys.settrace" title="sys.settrace"><code class="xref py py-func docutils literal notranslate"><span class="pre">settrace()</span></code></a> in order to enable the runtime tracing machinery,
  1885. but it doesn’t need to be the same tracing function (e.g. it could be a
  1886. low overhead tracing function that simply returns <code class="docutils literal notranslate"><span class="pre">None</span></code> to disable
  1887. itself immediately on each frame).</p>
  1888. <p>For more information on code and frame objects, refer to <a class="reference internal" href="../reference/datamodel.html#types"><span class="std std-ref">The standard type hierarchy</span></a>.</p>
  1889. <p class="audit-hook">Raises an <a class="reference internal" href="#auditing"><span class="std std-ref">auditing event</span></a> <code class="docutils literal notranslate"><span class="pre">sys.settrace</span></code> with no arguments.</p>
  1890. <div class="impl-detail compound">
  1891. <p><strong>CPython implementation detail:</strong> The <a class="reference internal" href="#sys.settrace" title="sys.settrace"><code class="xref py py-func docutils literal notranslate"><span class="pre">settrace()</span></code></a> function is intended only for implementing debuggers,
  1892. profilers, coverage tools and the like. Its behavior is part of the
  1893. implementation platform, rather than part of the language definition, and
  1894. thus may not be available in all Python implementations.</p>
  1895. </div>
  1896. <div class="versionchanged">
  1897. <p><span class="versionmodified changed">Changed in version 3.7: </span><code class="docutils literal notranslate"><span class="pre">'opcode'</span></code> event type added; <a class="reference internal" href="../reference/datamodel.html#frame.f_trace_lines" title="frame.f_trace_lines"><code class="xref py py-attr docutils literal notranslate"><span class="pre">f_trace_lines</span></code></a> and
  1898. <a class="reference internal" href="../reference/datamodel.html#frame.f_trace_opcodes" title="frame.f_trace_opcodes"><code class="xref py py-attr docutils literal notranslate"><span class="pre">f_trace_opcodes</span></code></a> attributes added to frames</p>
  1899. </div>
  1900. <div class="versionchanged">
  1901. <p><span class="versionmodified changed">Changed in version 3.12: </span><code class="docutils literal notranslate"><span class="pre">'opcode'</span></code> event will only be emitted if <a class="reference internal" href="../reference/datamodel.html#frame.f_trace_opcodes" title="frame.f_trace_opcodes"><code class="xref py py-attr docutils literal notranslate"><span class="pre">f_trace_opcodes</span></code></a>
  1902. of at least one frame has been set to <a class="reference internal" href="constants.html#True" title="True"><code class="xref py py-const docutils literal notranslate"><span class="pre">True</span></code></a> before <a class="reference internal" href="#sys.settrace" title="sys.settrace"><code class="xref py py-func docutils literal notranslate"><span class="pre">settrace()</span></code></a>
  1903. is called. This behavior will be changed back in 3.13 to be consistent with
  1904. previous versions.</p>
  1905. </div>
  1906. </dd></dl>
  1907. <dl class="py function">
  1908. <dt class="sig sig-object py" id="sys.set_asyncgen_hooks">
  1909. <span class="sig-prename descclassname"><span class="pre">sys.</span></span><span class="sig-name descname"><span class="pre">set_asyncgen_hooks</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="pre">[firstiter]</span> <span class="pre">[,</span> <span class="pre">finalizer]</span></em><span class="sig-paren">)</span><a class="headerlink" href="#sys.set_asyncgen_hooks" title="Link to this definition">¶</a></dt>
  1910. <dd><p>Accepts two optional keyword arguments which are callables that accept an
  1911. <a class="reference internal" href="../glossary.html#term-asynchronous-generator-iterator"><span class="xref std std-term">asynchronous generator iterator</span></a> as an argument. The <em>firstiter</em>
  1912. callable will be called when an asynchronous generator is iterated for the
  1913. first time. The <em>finalizer</em> will be called when an asynchronous generator
  1914. is about to be garbage collected.</p>
  1915. <p class="audit-hook">Raises an <a class="reference internal" href="#auditing"><span class="std std-ref">auditing event</span></a> <code class="docutils literal notranslate"><span class="pre">sys.set_asyncgen_hooks_firstiter</span></code> with no arguments.</p>
  1916. <p class="audit-hook">Raises an <a class="reference internal" href="#auditing"><span class="std std-ref">auditing event</span></a> <code class="docutils literal notranslate"><span class="pre">sys.set_asyncgen_hooks_finalizer</span></code> with no arguments.</p>
  1917. <p>Two auditing events are raised because the underlying API consists of two
  1918. calls, each of which must raise its own event.</p>
  1919. <div class="versionadded">
  1920. <p><span class="versionmodified added">New in version 3.6: </span>See <span class="target" id="index-30"></span><a class="pep reference external" href="https://peps.python.org/pep-0525/"><strong>PEP 525</strong></a> for more details, and for a reference example of a
  1921. <em>finalizer</em> method see the implementation of
  1922. <code class="docutils literal notranslate"><span class="pre">asyncio.Loop.shutdown_asyncgens</span></code> in
  1923. <a class="reference external" href="https://github.com/python/cpython/tree/3.12/Lib/asyncio/base_events.py">Lib/asyncio/base_events.py</a></p>
  1924. </div>
  1925. <div class="admonition note">
  1926. <p class="admonition-title">Note</p>
  1927. <p>This function has been added on a provisional basis (see <span class="target" id="index-31"></span><a class="pep reference external" href="https://peps.python.org/pep-0411/"><strong>PEP 411</strong></a>
  1928. for details.)</p>
  1929. </div>
  1930. </dd></dl>
  1931. <dl class="py function">
  1932. <dt class="sig sig-object py" id="sys.set_coroutine_origin_tracking_depth">
  1933. <span class="sig-prename descclassname"><span class="pre">sys.</span></span><span class="sig-name descname"><span class="pre">set_coroutine_origin_tracking_depth</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">depth</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#sys.set_coroutine_origin_tracking_depth" title="Link to this definition">¶</a></dt>
  1934. <dd><p>Allows enabling or disabling coroutine origin tracking. When
  1935. enabled, the <code class="docutils literal notranslate"><span class="pre">cr_origin</span></code> attribute on coroutine objects will
  1936. contain a tuple of (filename, line number, function name) tuples
  1937. describing the traceback where the coroutine object was created,
  1938. with the most recent call first. When disabled, <code class="docutils literal notranslate"><span class="pre">cr_origin</span></code> will
  1939. be None.</p>
  1940. <p>To enable, pass a <em>depth</em> value greater than zero; this sets the
  1941. number of frames whose information will be captured. To disable,
  1942. pass set <em>depth</em> to zero.</p>
  1943. <p>This setting is thread-specific.</p>
  1944. <div class="versionadded">
  1945. <p><span class="versionmodified added">New in version 3.7.</span></p>
  1946. </div>
  1947. <div class="admonition note">
  1948. <p class="admonition-title">Note</p>
  1949. <p>This function has been added on a provisional basis (see <span class="target" id="index-32"></span><a class="pep reference external" href="https://peps.python.org/pep-0411/"><strong>PEP 411</strong></a>
  1950. for details.) Use it only for debugging purposes.</p>
  1951. </div>
  1952. </dd></dl>
  1953. <dl class="py function">
  1954. <dt class="sig sig-object py" id="sys.activate_stack_trampoline">
  1955. <span class="sig-prename descclassname"><span class="pre">sys.</span></span><span class="sig-name descname"><span class="pre">activate_stack_trampoline</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">backend</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">/</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#sys.activate_stack_trampoline" title="Link to this definition">¶</a></dt>
  1956. <dd><p>Activate the stack profiler trampoline <em>backend</em>.
  1957. The only supported backend is <code class="docutils literal notranslate"><span class="pre">&quot;perf&quot;</span></code>.</p>
  1958. <div class="availability docutils container">
  1959. <p><a class="reference internal" href="intro.html#availability"><span class="std std-ref">Availability</span></a>: Linux.</p>
  1960. </div>
  1961. <div class="versionadded">
  1962. <p><span class="versionmodified added">New in version 3.12.</span></p>
  1963. </div>
  1964. <div class="admonition seealso">
  1965. <p class="admonition-title">See also</p>
  1966. <ul class="simple">
  1967. <li><p><a class="reference internal" href="../howto/perf_profiling.html#perf-profiling"><span class="std std-ref">Python support for the Linux perf profiler</span></a></p></li>
  1968. <li><p><a class="reference external" href="https://perf.wiki.kernel.org">https://perf.wiki.kernel.org</a></p></li>
  1969. </ul>
  1970. </div>
  1971. </dd></dl>
  1972. <dl class="py function">
  1973. <dt class="sig sig-object py" id="sys.deactivate_stack_trampoline">
  1974. <span class="sig-prename descclassname"><span class="pre">sys.</span></span><span class="sig-name descname"><span class="pre">deactivate_stack_trampoline</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#sys.deactivate_stack_trampoline" title="Link to this definition">¶</a></dt>
  1975. <dd><p>Deactivate the current stack profiler trampoline backend.</p>
  1976. <p>If no stack profiler is activated, this function has no effect.</p>
  1977. <div class="availability docutils container">
  1978. <p><a class="reference internal" href="intro.html#availability"><span class="std std-ref">Availability</span></a>: Linux.</p>
  1979. </div>
  1980. <div class="versionadded">
  1981. <p><span class="versionmodified added">New in version 3.12.</span></p>
  1982. </div>
  1983. </dd></dl>
  1984. <dl class="py function">
  1985. <dt class="sig sig-object py" id="sys.is_stack_trampoline_active">
  1986. <span class="sig-prename descclassname"><span class="pre">sys.</span></span><span class="sig-name descname"><span class="pre">is_stack_trampoline_active</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#sys.is_stack_trampoline_active" title="Link to this definition">¶</a></dt>
  1987. <dd><p>Return <code class="docutils literal notranslate"><span class="pre">True</span></code> if a stack profiler trampoline is active.</p>
  1988. <div class="availability docutils container">
  1989. <p><a class="reference internal" href="intro.html#availability"><span class="std std-ref">Availability</span></a>: Linux.</p>
  1990. </div>
  1991. <div class="versionadded">
  1992. <p><span class="versionmodified added">New in version 3.12.</span></p>
  1993. </div>
  1994. </dd></dl>
  1995. <dl class="py function">
  1996. <dt class="sig sig-object py" id="sys._enablelegacywindowsfsencoding">
  1997. <span class="sig-prename descclassname"><span class="pre">sys.</span></span><span class="sig-name descname"><span class="pre">_enablelegacywindowsfsencoding</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#sys._enablelegacywindowsfsencoding" title="Link to this definition">¶</a></dt>
  1998. <dd><p>Changes the <a class="reference internal" href="../glossary.html#term-filesystem-encoding-and-error-handler"><span class="xref std std-term">filesystem encoding and error handler</span></a> to ‘mbcs’ and
  1999. ‘replace’ respectively, for consistency with versions of Python prior to
  2000. 3.6.</p>
  2001. <p>This is equivalent to defining the <span class="target" id="index-33"></span><a class="reference internal" href="../using/cmdline.html#envvar-PYTHONLEGACYWINDOWSFSENCODING"><code class="xref std std-envvar docutils literal notranslate"><span class="pre">PYTHONLEGACYWINDOWSFSENCODING</span></code></a>
  2002. environment variable before launching Python.</p>
  2003. <p>See also <a class="reference internal" href="#sys.getfilesystemencoding" title="sys.getfilesystemencoding"><code class="xref py py-func docutils literal notranslate"><span class="pre">sys.getfilesystemencoding()</span></code></a> and
  2004. <a class="reference internal" href="#sys.getfilesystemencodeerrors" title="sys.getfilesystemencodeerrors"><code class="xref py py-func docutils literal notranslate"><span class="pre">sys.getfilesystemencodeerrors()</span></code></a>.</p>
  2005. <div class="availability docutils container">
  2006. <p><a class="reference internal" href="intro.html#availability"><span class="std std-ref">Availability</span></a>: Windows.</p>
  2007. </div>
  2008. <div class="versionadded">
  2009. <p><span class="versionmodified added">New in version 3.6: </span>See <span class="target" id="index-34"></span><a class="pep reference external" href="https://peps.python.org/pep-0529/"><strong>PEP 529</strong></a> for more details.</p>
  2010. </div>
  2011. </dd></dl>
  2012. <dl class="py data">
  2013. <dt class="sig sig-object py" id="sys.stdin">
  2014. <span class="sig-prename descclassname"><span class="pre">sys.</span></span><span class="sig-name descname"><span class="pre">stdin</span></span><a class="headerlink" href="#sys.stdin" title="Link to this definition">¶</a></dt>
  2015. <dt class="sig sig-object py" id="sys.stdout">
  2016. <span class="sig-prename descclassname"><span class="pre">sys.</span></span><span class="sig-name descname"><span class="pre">stdout</span></span><a class="headerlink" href="#sys.stdout" title="Link to this definition">¶</a></dt>
  2017. <dt class="sig sig-object py" id="sys.stderr">
  2018. <span class="sig-prename descclassname"><span class="pre">sys.</span></span><span class="sig-name descname"><span class="pre">stderr</span></span><a class="headerlink" href="#sys.stderr" title="Link to this definition">¶</a></dt>
  2019. <dd><p><a class="reference internal" href="../glossary.html#term-file-object"><span class="xref std std-term">File objects</span></a> used by the interpreter for standard
  2020. input, output and errors:</p>
  2021. <ul class="simple">
  2022. <li><p><code class="docutils literal notranslate"><span class="pre">stdin</span></code> is used for all interactive input (including calls to
  2023. <a class="reference internal" href="functions.html#input" title="input"><code class="xref py py-func docutils literal notranslate"><span class="pre">input()</span></code></a>);</p></li>
  2024. <li><p><code class="docutils literal notranslate"><span class="pre">stdout</span></code> is used for the output of <a class="reference internal" href="functions.html#print" title="print"><code class="xref py py-func docutils literal notranslate"><span class="pre">print()</span></code></a> and <a class="reference internal" href="../glossary.html#term-expression"><span class="xref std std-term">expression</span></a>
  2025. statements and for the prompts of <a class="reference internal" href="functions.html#input" title="input"><code class="xref py py-func docutils literal notranslate"><span class="pre">input()</span></code></a>;</p></li>
  2026. <li><p>The interpreter’s own prompts and its error messages go to <code class="docutils literal notranslate"><span class="pre">stderr</span></code>.</p></li>
  2027. </ul>
  2028. <p>These streams are regular <a class="reference internal" href="../glossary.html#term-text-file"><span class="xref std std-term">text files</span></a> like those
  2029. returned by the <a class="reference internal" href="functions.html#open" title="open"><code class="xref py py-func docutils literal notranslate"><span class="pre">open()</span></code></a> function. Their parameters are chosen as
  2030. follows:</p>
  2031. <ul>
  2032. <li><p>The encoding and error handling are is initialized from
  2033. <a class="reference internal" href="../c-api/init_config.html#c.PyConfig.stdio_encoding" title="PyConfig.stdio_encoding"><code class="xref c c-member docutils literal notranslate"><span class="pre">PyConfig.stdio_encoding</span></code></a> and <a class="reference internal" href="../c-api/init_config.html#c.PyConfig.stdio_errors" title="PyConfig.stdio_errors"><code class="xref c c-member docutils literal notranslate"><span class="pre">PyConfig.stdio_errors</span></code></a>.</p>
  2034. <p>On Windows, UTF-8 is used for the console device. Non-character
  2035. devices such as disk files and pipes use the system locale
  2036. encoding (i.e. the ANSI codepage). Non-console character
  2037. devices such as NUL (i.e. where <code class="docutils literal notranslate"><span class="pre">isatty()</span></code> returns <code class="docutils literal notranslate"><span class="pre">True</span></code>) use the
  2038. value of the console input and output codepages at startup,
  2039. respectively for stdin and stdout/stderr. This defaults to the
  2040. system <a class="reference internal" href="../glossary.html#term-locale-encoding"><span class="xref std std-term">locale encoding</span></a> if the process is not initially attached
  2041. to a console.</p>
  2042. <p>The special behaviour of the console can be overridden
  2043. by setting the environment variable PYTHONLEGACYWINDOWSSTDIO
  2044. before starting Python. In that case, the console codepages are
  2045. used as for any other character device.</p>
  2046. <p>Under all platforms, you can override the character encoding by
  2047. setting the <span class="target" id="index-35"></span><a class="reference internal" href="../using/cmdline.html#envvar-PYTHONIOENCODING"><code class="xref std std-envvar docutils literal notranslate"><span class="pre">PYTHONIOENCODING</span></code></a> environment variable before
  2048. starting Python or by using the new <a class="reference internal" href="../using/cmdline.html#cmdoption-X"><code class="xref std std-option docutils literal notranslate"><span class="pre">-X</span></code></a> <code class="docutils literal notranslate"><span class="pre">utf8</span></code> command
  2049. line option and <span class="target" id="index-36"></span><a class="reference internal" href="../using/cmdline.html#envvar-PYTHONUTF8"><code class="xref std std-envvar docutils literal notranslate"><span class="pre">PYTHONUTF8</span></code></a> environment variable. However,
  2050. for the Windows console, this only applies when
  2051. <span class="target" id="index-37"></span><a class="reference internal" href="../using/cmdline.html#envvar-PYTHONLEGACYWINDOWSSTDIO"><code class="xref std std-envvar docutils literal notranslate"><span class="pre">PYTHONLEGACYWINDOWSSTDIO</span></code></a> is also set.</p>
  2052. </li>
  2053. <li><p>When interactive, the <code class="docutils literal notranslate"><span class="pre">stdout</span></code> stream is line-buffered. Otherwise,
  2054. it is block-buffered like regular text files. The <code class="docutils literal notranslate"><span class="pre">stderr</span></code> stream
  2055. is line-buffered in both cases. You can make both streams unbuffered
  2056. by passing the <a class="reference internal" href="../using/cmdline.html#cmdoption-u"><code class="xref std std-option docutils literal notranslate"><span class="pre">-u</span></code></a> command-line option or setting the
  2057. <span class="target" id="index-38"></span><a class="reference internal" href="../using/cmdline.html#envvar-PYTHONUNBUFFERED"><code class="xref std std-envvar docutils literal notranslate"><span class="pre">PYTHONUNBUFFERED</span></code></a> environment variable.</p></li>
  2058. </ul>
  2059. <div class="versionchanged">
  2060. <p><span class="versionmodified changed">Changed in version 3.9: </span>Non-interactive <code class="docutils literal notranslate"><span class="pre">stderr</span></code> is now line-buffered instead of fully
  2061. buffered.</p>
  2062. </div>
  2063. <div class="admonition note">
  2064. <p class="admonition-title">Note</p>
  2065. <p>To write or read binary data from/to the standard streams, use the
  2066. underlying binary <a class="reference internal" href="io.html#io.TextIOBase.buffer" title="io.TextIOBase.buffer"><code class="xref py py-data docutils literal notranslate"><span class="pre">buffer</span></code></a> object. For example, to
  2067. write bytes to <a class="reference internal" href="#sys.stdout" title="sys.stdout"><code class="xref py py-data docutils literal notranslate"><span class="pre">stdout</span></code></a>, use <code class="docutils literal notranslate"><span class="pre">sys.stdout.buffer.write(b'abc')</span></code>.</p>
  2068. <p>However, if you are writing a library (and do not control in which
  2069. context its code will be executed), be aware that the standard streams
  2070. may be replaced with file-like objects like <a class="reference internal" href="io.html#io.StringIO" title="io.StringIO"><code class="xref py py-class docutils literal notranslate"><span class="pre">io.StringIO</span></code></a> which
  2071. do not support the <code class="xref py py-attr docutils literal notranslate"><span class="pre">buffer</span></code> attribute.</p>
  2072. </div>
  2073. </dd></dl>
  2074. <dl class="py data">
  2075. <dt class="sig sig-object py" id="sys.__stdin__">
  2076. <span class="sig-prename descclassname"><span class="pre">sys.</span></span><span class="sig-name descname"><span class="pre">__stdin__</span></span><a class="headerlink" href="#sys.__stdin__" title="Link to this definition">¶</a></dt>
  2077. <dt class="sig sig-object py" id="sys.__stdout__">
  2078. <span class="sig-prename descclassname"><span class="pre">sys.</span></span><span class="sig-name descname"><span class="pre">__stdout__</span></span><a class="headerlink" href="#sys.__stdout__" title="Link to this definition">¶</a></dt>
  2079. <dt class="sig sig-object py" id="sys.__stderr__">
  2080. <span class="sig-prename descclassname"><span class="pre">sys.</span></span><span class="sig-name descname"><span class="pre">__stderr__</span></span><a class="headerlink" href="#sys.__stderr__" title="Link to this definition">¶</a></dt>
  2081. <dd><p>These objects contain the original values of <code class="docutils literal notranslate"><span class="pre">stdin</span></code>, <code class="docutils literal notranslate"><span class="pre">stderr</span></code> and
  2082. <code class="docutils literal notranslate"><span class="pre">stdout</span></code> at the start of the program. They are used during finalization,
  2083. and could be useful to print to the actual standard stream no matter if the
  2084. <code class="docutils literal notranslate"><span class="pre">sys.std*</span></code> object has been redirected.</p>
  2085. <p>It can also be used to restore the actual files to known working file objects
  2086. in case they have been overwritten with a broken object. However, the
  2087. preferred way to do this is to explicitly save the previous stream before
  2088. replacing it, and restore the saved object.</p>
  2089. <div class="admonition note">
  2090. <p class="admonition-title">Note</p>
  2091. <p>Under some conditions <code class="docutils literal notranslate"><span class="pre">stdin</span></code>, <code class="docutils literal notranslate"><span class="pre">stdout</span></code> and <code class="docutils literal notranslate"><span class="pre">stderr</span></code> as well as the
  2092. original values <code class="docutils literal notranslate"><span class="pre">__stdin__</span></code>, <code class="docutils literal notranslate"><span class="pre">__stdout__</span></code> and <code class="docutils literal notranslate"><span class="pre">__stderr__</span></code> can be
  2093. <code class="docutils literal notranslate"><span class="pre">None</span></code>. It is usually the case for Windows GUI apps that aren’t connected
  2094. to a console and Python apps started with <strong class="program">pythonw</strong>.</p>
  2095. </div>
  2096. </dd></dl>
  2097. <dl class="py data">
  2098. <dt class="sig sig-object py" id="sys.stdlib_module_names">
  2099. <span class="sig-prename descclassname"><span class="pre">sys.</span></span><span class="sig-name descname"><span class="pre">stdlib_module_names</span></span><a class="headerlink" href="#sys.stdlib_module_names" title="Link to this definition">¶</a></dt>
  2100. <dd><p>A frozenset of strings containing the names of standard library modules.</p>
  2101. <p>It is the same on all platforms. Modules which are not available on
  2102. some platforms and modules disabled at Python build are also listed.
  2103. All module kinds are listed: pure Python, built-in, frozen and extension
  2104. modules. Test modules are excluded.</p>
  2105. <p>For packages, only the main package is listed: sub-packages and sub-modules
  2106. are not listed. For example, the <code class="docutils literal notranslate"><span class="pre">email</span></code> package is listed, but the
  2107. <code class="docutils literal notranslate"><span class="pre">email.mime</span></code> sub-package and the <code class="docutils literal notranslate"><span class="pre">email.message</span></code> sub-module are not
  2108. listed.</p>
  2109. <p>See also the <a class="reference internal" href="#sys.builtin_module_names" title="sys.builtin_module_names"><code class="xref py py-data docutils literal notranslate"><span class="pre">sys.builtin_module_names</span></code></a> list.</p>
  2110. <div class="versionadded">
  2111. <p><span class="versionmodified added">New in version 3.10.</span></p>
  2112. </div>
  2113. </dd></dl>
  2114. <dl class="py data">
  2115. <dt class="sig sig-object py" id="sys.thread_info">
  2116. <span class="sig-prename descclassname"><span class="pre">sys.</span></span><span class="sig-name descname"><span class="pre">thread_info</span></span><a class="headerlink" href="#sys.thread_info" title="Link to this definition">¶</a></dt>
  2117. <dd><p>A <a class="reference internal" href="../glossary.html#term-named-tuple"><span class="xref std std-term">named tuple</span></a> holding information about the thread
  2118. implementation.</p>
  2119. <dl class="py attribute">
  2120. <dt class="sig sig-object py" id="sys.thread_info.name">
  2121. <span class="sig-prename descclassname"><span class="pre">thread_info.</span></span><span class="sig-name descname"><span class="pre">name</span></span><a class="headerlink" href="#sys.thread_info.name" title="Link to this definition">¶</a></dt>
  2122. <dd><p>The name of the thread implementation:</p>
  2123. <ul class="simple">
  2124. <li><p><code class="docutils literal notranslate"><span class="pre">&quot;nt&quot;</span></code>: Windows threads</p></li>
  2125. <li><p><code class="docutils literal notranslate"><span class="pre">&quot;pthread&quot;</span></code>: POSIX threads</p></li>
  2126. <li><p><code class="docutils literal notranslate"><span class="pre">&quot;pthread-stubs&quot;</span></code>: stub POSIX threads
  2127. (on WebAssembly platforms without threading support)</p></li>
  2128. <li><p><code class="docutils literal notranslate"><span class="pre">&quot;solaris&quot;</span></code>: Solaris threads</p></li>
  2129. </ul>
  2130. </dd></dl>
  2131. <dl class="py attribute">
  2132. <dt class="sig sig-object py" id="sys.thread_info.lock">
  2133. <span class="sig-prename descclassname"><span class="pre">thread_info.</span></span><span class="sig-name descname"><span class="pre">lock</span></span><a class="headerlink" href="#sys.thread_info.lock" title="Link to this definition">¶</a></dt>
  2134. <dd><p>The name of the lock implementation:</p>
  2135. <ul class="simple">
  2136. <li><p><code class="docutils literal notranslate"><span class="pre">&quot;semaphore&quot;</span></code>: a lock uses a semaphore</p></li>
  2137. <li><p><code class="docutils literal notranslate"><span class="pre">&quot;mutex+cond&quot;</span></code>: a lock uses a mutex and a condition variable</p></li>
  2138. <li><p><code class="docutils literal notranslate"><span class="pre">None</span></code> if this information is unknown</p></li>
  2139. </ul>
  2140. </dd></dl>
  2141. <dl class="py attribute">
  2142. <dt class="sig sig-object py" id="sys.thread_info.version">
  2143. <span class="sig-prename descclassname"><span class="pre">thread_info.</span></span><span class="sig-name descname"><span class="pre">version</span></span><a class="headerlink" href="#sys.thread_info.version" title="Link to this definition">¶</a></dt>
  2144. <dd><p>The name and version of the thread library.
  2145. It is a string, or <code class="docutils literal notranslate"><span class="pre">None</span></code> if this information is unknown.</p>
  2146. </dd></dl>
  2147. <div class="versionadded">
  2148. <p><span class="versionmodified added">New in version 3.3.</span></p>
  2149. </div>
  2150. </dd></dl>
  2151. <dl class="py data">
  2152. <dt class="sig sig-object py" id="sys.tracebacklimit">
  2153. <span class="sig-prename descclassname"><span class="pre">sys.</span></span><span class="sig-name descname"><span class="pre">tracebacklimit</span></span><a class="headerlink" href="#sys.tracebacklimit" title="Link to this definition">¶</a></dt>
  2154. <dd><p>When this variable is set to an integer value, it determines the maximum number
  2155. of levels of traceback information printed when an unhandled exception occurs.
  2156. The default is <code class="docutils literal notranslate"><span class="pre">1000</span></code>. When set to <code class="docutils literal notranslate"><span class="pre">0</span></code> or less, all traceback information
  2157. is suppressed and only the exception type and value are printed.</p>
  2158. </dd></dl>
  2159. <dl class="py function">
  2160. <dt class="sig sig-object py" id="sys.unraisablehook">
  2161. <span class="sig-prename descclassname"><span class="pre">sys.</span></span><span class="sig-name descname"><span class="pre">unraisablehook</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">unraisable</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">/</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#sys.unraisablehook" title="Link to this definition">¶</a></dt>
  2162. <dd><p>Handle an unraisable exception.</p>
  2163. <p>Called when an exception has occurred but there is no way for Python to
  2164. handle it. For example, when a destructor raises an exception or during
  2165. garbage collection (<a class="reference internal" href="gc.html#gc.collect" title="gc.collect"><code class="xref py py-func docutils literal notranslate"><span class="pre">gc.collect()</span></code></a>).</p>
  2166. <p>The <em>unraisable</em> argument has the following attributes:</p>
  2167. <ul class="simple">
  2168. <li><p><code class="xref py py-attr docutils literal notranslate"><span class="pre">exc_type</span></code>: Exception type.</p></li>
  2169. <li><p><code class="xref py py-attr docutils literal notranslate"><span class="pre">exc_value</span></code>: Exception value, can be <code class="docutils literal notranslate"><span class="pre">None</span></code>.</p></li>
  2170. <li><p><code class="xref py py-attr docutils literal notranslate"><span class="pre">exc_traceback</span></code>: Exception traceback, can be <code class="docutils literal notranslate"><span class="pre">None</span></code>.</p></li>
  2171. <li><p><code class="xref py py-attr docutils literal notranslate"><span class="pre">err_msg</span></code>: Error message, can be <code class="docutils literal notranslate"><span class="pre">None</span></code>.</p></li>
  2172. <li><p><code class="xref py py-attr docutils literal notranslate"><span class="pre">object</span></code>: Object causing the exception, can be <code class="docutils literal notranslate"><span class="pre">None</span></code>.</p></li>
  2173. </ul>
  2174. <p>The default hook formats <code class="xref py py-attr docutils literal notranslate"><span class="pre">err_msg</span></code> and <code class="xref py py-attr docutils literal notranslate"><span class="pre">object</span></code> as:
  2175. <code class="docutils literal notranslate"><span class="pre">f'{err_msg}:</span> <span class="pre">{object!r}'</span></code>; use “Exception ignored in” error message
  2176. if <code class="xref py py-attr docutils literal notranslate"><span class="pre">err_msg</span></code> is <code class="docutils literal notranslate"><span class="pre">None</span></code>.</p>
  2177. <p><a class="reference internal" href="#sys.unraisablehook" title="sys.unraisablehook"><code class="xref py py-func docutils literal notranslate"><span class="pre">sys.unraisablehook()</span></code></a> can be overridden to control how unraisable
  2178. exceptions are handled.</p>
  2179. <div class="admonition seealso">
  2180. <p class="admonition-title">See also</p>
  2181. <p><a class="reference internal" href="#sys.excepthook" title="sys.excepthook"><code class="xref py py-func docutils literal notranslate"><span class="pre">excepthook()</span></code></a> which handles uncaught exceptions.</p>
  2182. </div>
  2183. <div class="admonition warning">
  2184. <p class="admonition-title">Warning</p>
  2185. <p>Storing <code class="xref py py-attr docutils literal notranslate"><span class="pre">exc_value</span></code> using a custom hook can create a reference cycle.
  2186. It should be cleared explicitly to break the reference cycle when the
  2187. exception is no longer needed.</p>
  2188. <p>Storing <code class="xref py py-attr docutils literal notranslate"><span class="pre">object</span></code> using a custom hook can resurrect it if it is set to an
  2189. object which is being finalized. Avoid storing <code class="xref py py-attr docutils literal notranslate"><span class="pre">object</span></code> after the custom
  2190. hook completes to avoid resurrecting objects.</p>
  2191. </div>
  2192. <p class="audit-hook"><p>Raise an auditing event <code class="docutils literal notranslate"><span class="pre">sys.unraisablehook</span></code> with arguments
  2193. <em>hook</em>, <em>unraisable</em> when an exception that cannot be handled occurs.
  2194. The <em>unraisable</em> object is the same as what will be passed to the hook.
  2195. If no hook has been set, <em>hook</em> may be <code class="docutils literal notranslate"><span class="pre">None</span></code>.</p>
  2196. </p>
  2197. <div class="versionadded">
  2198. <p><span class="versionmodified added">New in version 3.8.</span></p>
  2199. </div>
  2200. </dd></dl>
  2201. <dl class="py data">
  2202. <dt class="sig sig-object py" id="sys.version">
  2203. <span class="sig-prename descclassname"><span class="pre">sys.</span></span><span class="sig-name descname"><span class="pre">version</span></span><a class="headerlink" href="#sys.version" title="Link to this definition">¶</a></dt>
  2204. <dd><p>A string containing the version number of the Python interpreter plus additional
  2205. information on the build number and compiler used. This string is displayed
  2206. when the interactive interpreter is started. Do not extract version information
  2207. out of it, rather, use <a class="reference internal" href="#sys.version_info" title="sys.version_info"><code class="xref py py-data docutils literal notranslate"><span class="pre">version_info</span></code></a> and the functions provided by the
  2208. <a class="reference internal" href="platform.html#module-platform" title="platform: Retrieves as much platform identifying data as possible."><code class="xref py py-mod docutils literal notranslate"><span class="pre">platform</span></code></a> module.</p>
  2209. </dd></dl>
  2210. <dl class="py data">
  2211. <dt class="sig sig-object py" id="sys.api_version">
  2212. <span class="sig-prename descclassname"><span class="pre">sys.</span></span><span class="sig-name descname"><span class="pre">api_version</span></span><a class="headerlink" href="#sys.api_version" title="Link to this definition">¶</a></dt>
  2213. <dd><p>The C API version for this interpreter. Programmers may find this useful when
  2214. debugging version conflicts between Python and extension modules.</p>
  2215. </dd></dl>
  2216. <dl class="py data">
  2217. <dt class="sig sig-object py" id="sys.version_info">
  2218. <span class="sig-prename descclassname"><span class="pre">sys.</span></span><span class="sig-name descname"><span class="pre">version_info</span></span><a class="headerlink" href="#sys.version_info" title="Link to this definition">¶</a></dt>
  2219. <dd><p>A tuple containing the five components of the version number: <em>major</em>, <em>minor</em>,
  2220. <em>micro</em>, <em>releaselevel</em>, and <em>serial</em>. All values except <em>releaselevel</em> are
  2221. integers; the release level is <code class="docutils literal notranslate"><span class="pre">'alpha'</span></code>, <code class="docutils literal notranslate"><span class="pre">'beta'</span></code>, <code class="docutils literal notranslate"><span class="pre">'candidate'</span></code>, or
  2222. <code class="docutils literal notranslate"><span class="pre">'final'</span></code>. The <code class="docutils literal notranslate"><span class="pre">version_info</span></code> value corresponding to the Python version 2.0
  2223. is <code class="docutils literal notranslate"><span class="pre">(2,</span> <span class="pre">0,</span> <span class="pre">0,</span> <span class="pre">'final',</span> <span class="pre">0)</span></code>. The components can also be accessed by name,
  2224. so <code class="docutils literal notranslate"><span class="pre">sys.version_info[0]</span></code> is equivalent to <code class="docutils literal notranslate"><span class="pre">sys.version_info.major</span></code>
  2225. and so on.</p>
  2226. <div class="versionchanged">
  2227. <p><span class="versionmodified changed">Changed in version 3.1: </span>Added named component attributes.</p>
  2228. </div>
  2229. </dd></dl>
  2230. <dl class="py data">
  2231. <dt class="sig sig-object py" id="sys.warnoptions">
  2232. <span class="sig-prename descclassname"><span class="pre">sys.</span></span><span class="sig-name descname"><span class="pre">warnoptions</span></span><a class="headerlink" href="#sys.warnoptions" title="Link to this definition">¶</a></dt>
  2233. <dd><p>This is an implementation detail of the warnings framework; do not modify this
  2234. value. Refer to the <a class="reference internal" href="warnings.html#module-warnings" title="warnings: Issue warning messages and control their disposition."><code class="xref py py-mod docutils literal notranslate"><span class="pre">warnings</span></code></a> module for more information on the warnings
  2235. framework.</p>
  2236. </dd></dl>
  2237. <dl class="py data">
  2238. <dt class="sig sig-object py" id="sys.winver">
  2239. <span class="sig-prename descclassname"><span class="pre">sys.</span></span><span class="sig-name descname"><span class="pre">winver</span></span><a class="headerlink" href="#sys.winver" title="Link to this definition">¶</a></dt>
  2240. <dd><p>The version number used to form registry keys on Windows platforms. This is
  2241. stored as string resource 1000 in the Python DLL. The value is normally the
  2242. major and minor versions of the running Python interpreter. It is provided in the <a class="reference internal" href="#module-sys" title="sys: Access system-specific parameters and functions."><code class="xref py py-mod docutils literal notranslate"><span class="pre">sys</span></code></a>
  2243. module for informational purposes; modifying this value has no effect on the
  2244. registry keys used by Python.</p>
  2245. <div class="availability docutils container">
  2246. <p><a class="reference internal" href="intro.html#availability"><span class="std std-ref">Availability</span></a>: Windows.</p>
  2247. </div>
  2248. </dd></dl>
  2249. <dl class="py data">
  2250. <dt class="sig sig-object py">
  2251. <span class="sig-prename descclassname"><span class="pre">sys.</span></span><span class="sig-name descname"><span class="pre">monitoring</span></span></dt>
  2252. <dd><p>Namespace containing functions and constants for register callbacks
  2253. and controlling monitoring events.
  2254. See <a class="reference internal" href="sys.monitoring.html#module-sys.monitoring" title="sys.monitoring: Access and control event monitoring"><code class="xref py py-mod docutils literal notranslate"><span class="pre">sys.monitoring</span></code></a> for details.</p>
  2255. </dd></dl>
  2256. <dl class="py data">
  2257. <dt class="sig sig-object py" id="sys._xoptions">
  2258. <span class="sig-prename descclassname"><span class="pre">sys.</span></span><span class="sig-name descname"><span class="pre">_xoptions</span></span><a class="headerlink" href="#sys._xoptions" title="Link to this definition">¶</a></dt>
  2259. <dd><p>A dictionary of the various implementation-specific flags passed through
  2260. the <a class="reference internal" href="../using/cmdline.html#cmdoption-X"><code class="xref std std-option docutils literal notranslate"><span class="pre">-X</span></code></a> command-line option. Option names are either mapped to
  2261. their values, if given explicitly, or to <a class="reference internal" href="constants.html#True" title="True"><code class="xref py py-const docutils literal notranslate"><span class="pre">True</span></code></a>. Example:</p>
  2262. <div class="highlight-shell-session notranslate"><div class="highlight"><pre><span></span><span class="gp">$ </span>./python<span class="w"> </span>-Xa<span class="o">=</span>b<span class="w"> </span>-Xc
  2263. <span class="go">Python 3.2a3+ (py3k, Oct 16 2010, 20:14:50)</span>
  2264. <span class="go">[GCC 4.4.3] on linux2</span>
  2265. <span class="go">Type &quot;help&quot;, &quot;copyright&quot;, &quot;credits&quot; or &quot;license&quot; for more information.</span>
  2266. <span class="go">&gt;&gt;&gt; import sys</span>
  2267. <span class="go">&gt;&gt;&gt; sys._xoptions</span>
  2268. <span class="go">{&#39;a&#39;: &#39;b&#39;, &#39;c&#39;: True}</span>
  2269. </pre></div>
  2270. </div>
  2271. <div class="impl-detail compound">
  2272. <p><strong>CPython implementation detail:</strong> This is a CPython-specific way of accessing options passed through
  2273. <a class="reference internal" href="../using/cmdline.html#cmdoption-X"><code class="xref std std-option docutils literal notranslate"><span class="pre">-X</span></code></a>. Other implementations may export them through other
  2274. means, or not at all.</p>
  2275. </div>
  2276. <div class="versionadded">
  2277. <p><span class="versionmodified added">New in version 3.2.</span></p>
  2278. </div>
  2279. </dd></dl>
  2280. <p class="rubric">Citations</p>
  2281. <div role="list" class="citation-list">
  2282. <div class="citation" id="c99" role="doc-biblioentry">
  2283. <span class="label"><span class="fn-bracket">[</span><a role="doc-backlink" href="#id1">C99</a><span class="fn-bracket">]</span></span>
  2284. <p>ISO/IEC 9899:1999. “Programming languages – C.” A public draft of this standard is available at <a class="reference external" href="https://www.open-std.org/jtc1/sc22/wg14/www/docs/n1256.pdf">https://www.open-std.org/jtc1/sc22/wg14/www/docs/n1256.pdf</a>.</p>
  2285. </div>
  2286. </div>
  2287. </section>
  2288. <div class="clearer"></div>
  2289. </div>
  2290. </div>
  2291. </div>
  2292. <div class="sphinxsidebar" role="navigation" aria-label="main navigation">
  2293. <div class="sphinxsidebarwrapper">
  2294. <div>
  2295. <h4>Previous topic</h4>
  2296. <p class="topless"><a href="python.html"
  2297. title="previous chapter">Python Runtime Services</a></p>
  2298. </div>
  2299. <div>
  2300. <h4>Next topic</h4>
  2301. <p class="topless"><a href="sys.monitoring.html"
  2302. title="next chapter"><code class="xref py py-mod docutils literal notranslate"><span class="pre">sys.monitoring</span></code> — Execution event monitoring</a></p>
  2303. </div>
  2304. <div role="note" aria-label="source link">
  2305. <h3>This Page</h3>
  2306. <ul class="this-page-menu">
  2307. <li><a href="../bugs.html">Report a Bug</a></li>
  2308. <li>
  2309. <a href="https://github.com/python/cpython/blob/main/Doc/library/sys.rst"
  2310. rel="nofollow">Show Source
  2311. </a>
  2312. </li>
  2313. </ul>
  2314. </div>
  2315. </div>
  2316. <div id="sidebarbutton" title="Collapse sidebar">
  2317. <span>«</span>
  2318. </div>
  2319. </div>
  2320. <div class="clearer"></div>
  2321. </div>
  2322. <div class="related" role="navigation" aria-label="related navigation">
  2323. <h3>Navigation</h3>
  2324. <ul>
  2325. <li class="right" style="margin-right: 10px">
  2326. <a href="../genindex.html" title="General Index"
  2327. >index</a></li>
  2328. <li class="right" >
  2329. <a href="../py-modindex.html" title="Python Module Index"
  2330. >modules</a> |</li>
  2331. <li class="right" >
  2332. <a href="sys.monitoring.html" title="sys.monitoring — Execution event monitoring"
  2333. >next</a> |</li>
  2334. <li class="right" >
  2335. <a href="python.html" title="Python Runtime Services"
  2336. >previous</a> |</li>
  2337. <li><img src="../_static/py.svg" alt="Python logo" style="vertical-align: middle; margin-top: -1px"/></li>
  2338. <li><a href="https://www.python.org/">Python</a> &#187;</li>
  2339. <li class="switchers">
  2340. <div class="language_switcher_placeholder"></div>
  2341. <div class="version_switcher_placeholder"></div>
  2342. </li>
  2343. <li>
  2344. </li>
  2345. <li id="cpython-language-and-version">
  2346. <a href="../index.html">3.12.3 Documentation</a> &#187;
  2347. </li>
  2348. <li class="nav-item nav-item-1"><a href="index.html" >The Python Standard Library</a> &#187;</li>
  2349. <li class="nav-item nav-item-2"><a href="python.html" >Python Runtime Services</a> &#187;</li>
  2350. <li class="nav-item nav-item-this"><a href=""><code class="xref py py-mod docutils literal notranslate"><span class="pre">sys</span></code> — System-specific parameters and functions</a></li>
  2351. <li class="right">
  2352. <div class="inline-search" role="search">
  2353. <form class="inline-search" action="../search.html" method="get">
  2354. <input placeholder="Quick search" aria-label="Quick search" type="search" name="q" id="search-box" />
  2355. <input type="submit" value="Go" />
  2356. </form>
  2357. </div>
  2358. |
  2359. </li>
  2360. <li class="right">
  2361. <label class="theme-selector-label">
  2362. Theme
  2363. <select class="theme-selector" oninput="activateTheme(this.value)">
  2364. <option value="auto" selected>Auto</option>
  2365. <option value="light">Light</option>
  2366. <option value="dark">Dark</option>
  2367. </select>
  2368. </label> |</li>
  2369. </ul>
  2370. </div>
  2371. <div class="footer">
  2372. &copy;
  2373. <a href="../copyright.html">
  2374. Copyright
  2375. </a>
  2376. 2001-2024, Python Software Foundation.
  2377. <br />
  2378. This page is licensed under the Python Software Foundation License Version 2.
  2379. <br />
  2380. Examples, recipes, and other code in the documentation are additionally licensed under the Zero Clause BSD License.
  2381. <br />
  2382. See <a href="/license.html">History and License</a> for more information.<br />
  2383. <br />
  2384. The Python Software Foundation is a non-profit corporation.
  2385. <a href="https://www.python.org/psf/donations/">Please donate.</a>
  2386. <br />
  2387. <br />
  2388. Last updated on Apr 09, 2024 (13:47 UTC).
  2389. <a href="/bugs.html">Found a bug</a>?
  2390. <br />
  2391. Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 7.2.6.
  2392. </div>
  2393. </body>
  2394. </html>
上海开阖软件有限公司 沪ICP备12045867号-1