diff options
Diffstat (limited to 'devdocs/python~3.12/library%2Fsys.html')
| -rw-r--r-- | devdocs/python~3.12/library%2Fsys.html | 607 |
1 files changed, 607 insertions, 0 deletions
diff --git a/devdocs/python~3.12/library%2Fsys.html b/devdocs/python~3.12/library%2Fsys.html new file mode 100644 index 00000000..952b4489 --- /dev/null +++ b/devdocs/python~3.12/library%2Fsys.html @@ -0,0 +1,607 @@ + <span id="sys-system-specific-parameters-and-functions"></span><h1>sys — System-specific parameters and functions</h1> <p>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.</p> <dl class="py data"> <dt class="sig sig-object py" id="sys.abiflags"> +<code>sys.abiflags</code> </dt> <dd> +<p>On POSIX systems where Python was built with the standard <code>configure</code> 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> <div class="versionchanged"> <p><span class="versionmodified changed">Changed in version 3.8: </span>Default flags became an empty string (<code>m</code> flag for pymalloc has been removed).</p> </div> <div class="versionadded"> <p><span class="versionmodified added">New in version 3.2.</span></p> </div> </dd> +</dl> <dl class="py function"> <dt class="sig sig-object py" id="sys.addaudithook"> +<code>sys.addaudithook(hook)</code> </dt> <dd> +<p>Append the callable <em>hook</em> to the list of active auditing hooks for the current (sub)interpreter.</p> <p>When an auditing event is raised through the <a class="reference internal" href="#sys.audit" title="sys.audit"><code>sys.audit()</code></a> function, each hook will be called in the order it was added with the event name and the tuple of arguments. Native hooks added by <a class="reference internal" href="../c-api/sys#c.PySys_AddAuditHook" title="PySys_AddAuditHook"><code>PySys_AddAuditHook()</code></a> are called first, followed by hooks added in the current (sub)interpreter. Hooks can then log the event, raise an exception to abort the operation, or terminate the process entirely.</p> <p>Note that audit hooks are primarily for collecting information about internal or otherwise unobservable actions, whether by Python or libraries written in Python. They are not suitable for implementing a “sandbox”. In particular, malicious code can trivially disable or bypass hooks added using this function. At a minimum, any security-sensitive hooks must be added using the C API <a class="reference internal" href="../c-api/sys#c.PySys_AddAuditHook" title="PySys_AddAuditHook"><code>PySys_AddAuditHook()</code></a> before initialising the runtime, and any modules allowing arbitrary memory modification (such as <a class="reference internal" href="ctypes#module-ctypes" title="ctypes: A foreign function library for Python."><code>ctypes</code></a>) should be completely removed or closely monitored.</p> <p class="audit-hook"></p> +<p>Calling <a class="reference internal" href="#sys.addaudithook" title="sys.addaudithook"><code>sys.addaudithook()</code></a> will itself raise an auditing event named <code>sys.addaudithook</code> with no arguments. If any existing hooks raise an exception derived from <a class="reference internal" href="exceptions#RuntimeError" title="RuntimeError"><code>RuntimeError</code></a>, the new hook will not be added and the exception suppressed. As a result, callers cannot assume that their hook has been added unless they control all existing hooks.</p> <p>See the <a class="reference internal" href="audit_events#audit-events"><span class="std std-ref">audit events table</span></a> for all events raised by 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> <div class="versionadded"> <p><span class="versionmodified added">New in version 3.8.</span></p> </div> <div class="versionchanged"> <p><span class="versionmodified changed">Changed in version 3.8.1: </span>Exceptions derived from <a class="reference internal" href="exceptions#Exception" title="Exception"><code>Exception</code></a> but not <a class="reference internal" href="exceptions#RuntimeError" title="RuntimeError"><code>RuntimeError</code></a> are no longer suppressed.</p> </div> <div class="impl-detail compound"> <p><strong>CPython implementation detail:</strong> When tracing is enabled (see <a class="reference internal" href="#sys.settrace" title="sys.settrace"><code>settrace()</code></a>), Python hooks are only traced if the callable has a <code>__cantrace__</code> member that is set to a true value. Otherwise, trace functions will skip the hook.</p> </div> </dd> +</dl> <dl class="py data"> <dt class="sig sig-object py" id="sys.argv"> +<code>sys.argv</code> </dt> <dd> +<p>The list of command line arguments passed to a Python script. <code>argv[0]</code> is the script name (it is operating system dependent whether this is a full pathname or not). If the command was executed using the <a class="reference internal" href="../using/cmdline#cmdoption-c"><code>-c</code></a> command line option to the interpreter, <code>argv[0]</code> is set to the string <code>'-c'</code>. If no script name was passed to the Python interpreter, <code>argv[0]</code> is the empty string.</p> <p>To loop over the standard input, or the list of files given on the command line, see the <a class="reference internal" href="fileinput#module-fileinput" title="fileinput: Loop over standard input or a list of files."><code>fileinput</code></a> module.</p> <p>See also <a class="reference internal" href="#sys.orig_argv" title="sys.orig_argv"><code>sys.orig_argv</code></a>.</p> <div class="admonition note"> <p class="admonition-title">Note</p> <p>On Unix, command line arguments are passed by bytes from OS. Python decodes them with filesystem encoding and “surrogateescape” error handler. When you need original bytes, you can get it by <code>[os.fsencode(arg) for arg in sys.argv]</code>.</p> </div> </dd> +</dl> <span class="target" id="auditing"></span><dl class="py function"> <dt class="sig sig-object py" id="sys.audit"> +<code>sys.audit(event, *args)</code> </dt> <dd> +<p id="index-2">Raise an auditing event and trigger any active auditing hooks. <em>event</em> is a string identifying the event, and <em>args</em> may contain optional arguments with more information about the event. The number and types of arguments for a given event are considered a public and stable API and should not be modified between releases.</p> <p>For example, one auditing event is named <code>os.chdir</code>. This event has one argument called <em>path</em> that will contain the requested new working directory.</p> <p><a class="reference internal" href="#sys.audit" title="sys.audit"><code>sys.audit()</code></a> will call the existing auditing hooks, passing the event name and arguments, and will re-raise the first exception from any hook. In general, if an exception is raised, it should not be handled and the process should be terminated as quickly as possible. This allows hook implementations to decide how to respond to particular events: they can merely log the event or abort the operation by raising an exception.</p> <p>Hooks are added using the <a class="reference internal" href="#sys.addaudithook" title="sys.addaudithook"><code>sys.addaudithook()</code></a> or <a class="reference internal" href="../c-api/sys#c.PySys_AddAuditHook" title="PySys_AddAuditHook"><code>PySys_AddAuditHook()</code></a> functions.</p> <p>The native equivalent of this function is <a class="reference internal" href="../c-api/sys#c.PySys_Audit" title="PySys_Audit"><code>PySys_Audit()</code></a>. Using the native function is preferred when possible.</p> <p>See the <a class="reference internal" href="audit_events#audit-events"><span class="std std-ref">audit events table</span></a> for all events raised by CPython.</p> <div class="versionadded"> <p><span class="versionmodified added">New in version 3.8.</span></p> </div> </dd> +</dl> <dl class="py data"> <dt class="sig sig-object py" id="sys.base_exec_prefix"> +<code>sys.base_exec_prefix</code> </dt> <dd> +<p>Set during Python startup, before <code>site.py</code> is run, to the same value as <a class="reference internal" href="#sys.exec_prefix" title="sys.exec_prefix"><code>exec_prefix</code></a>. If not running in a <a class="reference internal" href="venv#venv-def"><span class="std std-ref">virtual environment</span></a>, the values will stay the same; if <code>site.py</code> finds that a virtual environment is in use, the values of <a class="reference internal" href="#sys.prefix" title="sys.prefix"><code>prefix</code></a> and <a class="reference internal" href="#sys.exec_prefix" title="sys.exec_prefix"><code>exec_prefix</code></a> will be changed to point to the virtual environment, whereas <a class="reference internal" href="#sys.base_prefix" title="sys.base_prefix"><code>base_prefix</code></a> and <a class="reference internal" href="#sys.base_exec_prefix" title="sys.base_exec_prefix"><code>base_exec_prefix</code></a> will remain pointing to the base Python installation (the one which the virtual environment was created from).</p> <div class="versionadded"> <p><span class="versionmodified added">New in version 3.3.</span></p> </div> </dd> +</dl> <dl class="py data"> <dt class="sig sig-object py" id="sys.base_prefix"> +<code>sys.base_prefix</code> </dt> <dd> +<p>Set during Python startup, before <code>site.py</code> is run, to the same value as <a class="reference internal" href="#sys.prefix" title="sys.prefix"><code>prefix</code></a>. If not running in a <a class="reference internal" href="venv#venv-def"><span class="std std-ref">virtual environment</span></a>, the values will stay the same; if <code>site.py</code> finds that a virtual environment is in use, the values of <a class="reference internal" href="#sys.prefix" title="sys.prefix"><code>prefix</code></a> and <a class="reference internal" href="#sys.exec_prefix" title="sys.exec_prefix"><code>exec_prefix</code></a> will be changed to point to the virtual environment, whereas <a class="reference internal" href="#sys.base_prefix" title="sys.base_prefix"><code>base_prefix</code></a> and <a class="reference internal" href="#sys.base_exec_prefix" title="sys.base_exec_prefix"><code>base_exec_prefix</code></a> will remain pointing to the base Python installation (the one which the virtual environment was created from).</p> <div class="versionadded"> <p><span class="versionmodified added">New in version 3.3.</span></p> </div> </dd> +</dl> <dl class="py data"> <dt class="sig sig-object py" id="sys.byteorder"> +<code>sys.byteorder</code> </dt> <dd> +<p>An indicator of the native byte order. This will have the value <code>'big'</code> on big-endian (most-significant byte first) platforms, and <code>'little'</code> on little-endian (least-significant byte first) platforms.</p> </dd> +</dl> <dl class="py data"> <dt class="sig sig-object py" id="sys.builtin_module_names"> +<code>sys.builtin_module_names</code> </dt> <dd> +<p>A tuple of strings containing the names of all modules that are compiled into this Python interpreter. (This information is not available in any other way — <code>modules.keys()</code> only lists the imported modules.)</p> <p>See also the <a class="reference internal" href="#sys.stdlib_module_names" title="sys.stdlib_module_names"><code>sys.stdlib_module_names</code></a> list.</p> </dd> +</dl> <dl class="py function"> <dt class="sig sig-object py" id="sys.call_tracing"> +<code>sys.call_tracing(func, args)</code> </dt> <dd> +<p>Call <code>func(*args)</code>, while tracing is enabled. The tracing state is saved, and restored afterwards. This is intended to be called from a debugger from a checkpoint, to recursively debug or profile some other code.</p> <p>Tracing is suspended while calling a tracing function set by <a class="reference internal" href="#sys.settrace" title="sys.settrace"><code>settrace()</code></a> or <a class="reference internal" href="#sys.setprofile" title="sys.setprofile"><code>setprofile()</code></a> to avoid infinite recursion. <code>call_tracing()</code> enables explicit recursion of the tracing function.</p> </dd> +</dl> <dl class="py data"> <dt class="sig sig-object py" id="sys.copyright"> +<code>sys.copyright</code> </dt> <dd> +<p>A string containing the copyright pertaining to the Python interpreter.</p> </dd> +</dl> <dl class="py function"> <dt class="sig sig-object py" id="sys._clear_type_cache"> +<code>sys._clear_type_cache()</code> </dt> <dd> +<p>Clear the internal type cache. The type cache is used to speed up attribute and method lookups. Use the function <em>only</em> to drop unnecessary references during reference leak debugging.</p> <p>This function should be used for internal and specialized purposes only.</p> </dd> +</dl> <dl class="py function"> <dt class="sig sig-object py" id="sys._current_frames"> +<code>sys._current_frames()</code> </dt> <dd> +<p>Return a dictionary mapping each thread’s identifier to the topmost stack frame currently active in that thread at the time the function is called. Note that functions in the <a class="reference internal" href="traceback#module-traceback" title="traceback: Print or retrieve a stack traceback."><code>traceback</code></a> module can build the call stack given such a frame.</p> <p>This is most useful for debugging deadlock: this function does not require the deadlocked threads’ cooperation, and such threads’ call stacks are frozen for as long as they remain deadlocked. The frame returned for a non-deadlocked thread may bear no relationship to that thread’s current activity by the time calling code examines the frame.</p> <p>This function should be used for internal and specialized purposes only.</p> <p class="audit-hook">Raises an <a class="reference internal" href="#auditing"><span class="std std-ref">auditing event</span></a> <code>sys._current_frames</code> with no arguments.</p> </dd> +</dl> <dl class="py function"> <dt class="sig sig-object py" id="sys._current_exceptions"> +<code>sys._current_exceptions()</code> </dt> <dd> +<p>Return a dictionary mapping each thread’s identifier to the topmost exception currently active in that thread at the time the function is called. If a thread is not currently handling an exception, it is not included in the result dictionary.</p> <p>This is most useful for statistical profiling.</p> <p>This function should be used for internal and specialized purposes only.</p> <p class="audit-hook">Raises an <a class="reference internal" href="#auditing"><span class="std std-ref">auditing event</span></a> <code>sys._current_exceptions</code> with no arguments.</p> <div class="versionchanged"> <p><span class="versionmodified changed">Changed in version 3.12: </span>Each value in the dictionary is now a single exception instance, rather than a 3-tuple as returned from <code>sys.exc_info()</code>.</p> </div> </dd> +</dl> <dl class="py function"> <dt class="sig sig-object py" id="sys.breakpointhook"> +<code>sys.breakpointhook()</code> </dt> <dd> +<p>This hook function is called by built-in <a class="reference internal" href="functions#breakpoint" title="breakpoint"><code>breakpoint()</code></a>. By default, it drops you into the <a class="reference internal" href="pdb#module-pdb" title="pdb: The Python debugger for interactive interpreters."><code>pdb</code></a> debugger, but it can be set to any other function so that you can choose which debugger gets used.</p> <p>The signature of this function is dependent on what it calls. For example, the default binding (e.g. <code>pdb.set_trace()</code>) expects no arguments, but you might bind it to a function that expects additional arguments (positional and/or keyword). The built-in <code>breakpoint()</code> function passes its <code>*args</code> and <code>**kws</code> straight through. Whatever <code>breakpointhooks()</code> returns is returned from <code>breakpoint()</code>.</p> <p>The default implementation first consults the environment variable <span class="target" id="index-3"></span><a class="reference internal" href="../using/cmdline#envvar-PYTHONBREAKPOINT"><code>PYTHONBREAKPOINT</code></a>. If that is set to <code>"0"</code> then this function returns immediately; i.e. it is a no-op. If the environment variable is not set, or is set to the empty string, <code>pdb.set_trace()</code> is called. Otherwise this variable should name a function to run, using Python’s dotted-import nomenclature, e.g. <code>package.subpackage.module.function</code>. In this case, <code>package.subpackage.module</code> would be imported and the resulting module must have a callable named <code>function()</code>. This is run, passing in <code>*args</code> and <code>**kws</code>, and whatever <code>function()</code> returns, <code>sys.breakpointhook()</code> returns to the built-in <a class="reference internal" href="functions#breakpoint" title="breakpoint"><code>breakpoint()</code></a> function.</p> <p>Note that if anything goes wrong while importing the callable named by <span class="target" id="index-4"></span><a class="reference internal" href="../using/cmdline#envvar-PYTHONBREAKPOINT"><code>PYTHONBREAKPOINT</code></a>, a <a class="reference internal" href="exceptions#RuntimeWarning" title="RuntimeWarning"><code>RuntimeWarning</code></a> is reported and the breakpoint is ignored.</p> <p>Also note that if <code>sys.breakpointhook()</code> is overridden programmatically, <span class="target" id="index-5"></span><a class="reference internal" href="../using/cmdline#envvar-PYTHONBREAKPOINT"><code>PYTHONBREAKPOINT</code></a> is <em>not</em> consulted.</p> <div class="versionadded"> <p><span class="versionmodified added">New in version 3.7.</span></p> </div> </dd> +</dl> <dl class="py function"> <dt class="sig sig-object py" id="sys._debugmallocstats"> +<code>sys._debugmallocstats()</code> </dt> <dd> +<p>Print low-level information to stderr about the state of CPython’s memory allocator.</p> <p>If Python is <a class="reference internal" href="../using/configure#debug-build"><span class="std std-ref">built in debug mode</span></a> (<a class="reference internal" href="../using/configure#cmdoption-with-pydebug"><code>configure +--with-pydebug option</code></a>), it also performs some expensive internal consistency checks.</p> <div class="versionadded"> <p><span class="versionmodified added">New in version 3.3.</span></p> </div> <div class="impl-detail compound"> <p><strong>CPython implementation detail:</strong> This function is specific to CPython. The exact output format is not defined here, and may change.</p> </div> </dd> +</dl> <dl class="py data"> <dt class="sig sig-object py" id="sys.dllhandle"> +<code>sys.dllhandle</code> </dt> <dd> +<p>Integer specifying the handle of the Python DLL.</p> <div class="availability docutils container"> <p><a class="reference internal" href="https://docs.python.org/3.12/library/intro.html#availability"><span class="std std-ref">Availability</span></a>: Windows.</p> </div> </dd> +</dl> <dl class="py function"> <dt class="sig sig-object py" id="sys.displayhook"> +<code>sys.displayhook(value)</code> </dt> <dd> +<p>If <em>value</em> is not <code>None</code>, this function prints <code>repr(value)</code> to <code>sys.stdout</code>, and saves <em>value</em> in <code>builtins._</code>. If <code>repr(value)</code> is not encodable to <code>sys.stdout.encoding</code> with <code>sys.stdout.errors</code> error handler (which is probably <code>'strict'</code>), encode it to <code>sys.stdout.encoding</code> with <code>'backslashreplace'</code> error handler.</p> <p><code>sys.displayhook</code> is called on the result of evaluating an <a class="reference internal" href="../glossary#term-expression"><span class="xref std std-term">expression</span></a> entered in an interactive Python session. The display of these values can be customized by assigning another one-argument function to <code>sys.displayhook</code>.</p> <p>Pseudo-code:</p> <pre data-language="python">def displayhook(value): + if value is None: + return + # Set '_' to None to avoid recursion + builtins._ = None + text = repr(value) + try: + sys.stdout.write(text) + except UnicodeEncodeError: + bytes = text.encode(sys.stdout.encoding, 'backslashreplace') + if hasattr(sys.stdout, 'buffer'): + sys.stdout.buffer.write(bytes) + else: + text = bytes.decode(sys.stdout.encoding, 'strict') + sys.stdout.write(text) + sys.stdout.write("\n") + builtins._ = value +</pre> <div class="versionchanged"> <p><span class="versionmodified changed">Changed in version 3.2: </span>Use <code>'backslashreplace'</code> error handler on <a class="reference internal" href="exceptions#UnicodeEncodeError" title="UnicodeEncodeError"><code>UnicodeEncodeError</code></a>.</p> </div> </dd> +</dl> <dl class="py data"> <dt class="sig sig-object py" id="sys.dont_write_bytecode"> +<code>sys.dont_write_bytecode</code> </dt> <dd> +<p>If this is true, Python won’t try to write <code>.pyc</code> files on the import of source modules. This value is initially set to <code>True</code> or <code>False</code> depending on the <a class="reference internal" href="../using/cmdline#cmdoption-B"><code>-B</code></a> command line option and the <span class="target" id="index-6"></span><a class="reference internal" href="../using/cmdline#envvar-PYTHONDONTWRITEBYTECODE"><code>PYTHONDONTWRITEBYTECODE</code></a> environment variable, but you can set it yourself to control bytecode file generation.</p> </dd> +</dl> <dl class="py data"> <dt class="sig sig-object py" id="sys._emscripten_info"> +<code>sys._emscripten_info</code> </dt> <dd> +<p>A <a class="reference internal" href="../glossary#term-named-tuple"><span class="xref std std-term">named tuple</span></a> holding information about the environment on the <em>wasm32-emscripten</em> platform. The named tuple is provisional and may change in the future.</p> <dl class="py attribute"> <dt class="sig sig-object py" id="sys._emscripten_info.emscripten_version"> +<code>_emscripten_info.emscripten_version</code> </dt> <dd> +<p>Emscripten version as tuple of ints (major, minor, micro), e.g. <code>(3, 1, 8)</code>.</p> </dd> +</dl> <dl class="py attribute"> <dt class="sig sig-object py" id="sys._emscripten_info.runtime"> +<code>_emscripten_info.runtime</code> </dt> <dd> +<p>Runtime string, e.g. browser user agent, <code>'Node.js v14.18.2'</code>, or <code>'UNKNOWN'</code>.</p> </dd> +</dl> <dl class="py attribute"> <dt class="sig sig-object py" id="sys._emscripten_info.pthreads"> +<code>_emscripten_info.pthreads</code> </dt> <dd> +<p><code>True</code> if Python is compiled with Emscripten pthreads support.</p> </dd> +</dl> <dl class="py attribute"> <dt class="sig sig-object py" id="sys._emscripten_info.shared_memory"> +<code>_emscripten_info.shared_memory</code> </dt> <dd> +<p><code>True</code> if Python is compiled with shared memory support.</p> </dd> +</dl> <div class="availability docutils container"> <p><a class="reference internal" href="https://docs.python.org/3.12/library/intro.html#availability"><span class="std std-ref">Availability</span></a>: Emscripten.</p> </div> <div class="versionadded"> <p><span class="versionmodified added">New in version 3.11.</span></p> </div> </dd> +</dl> <dl class="py data"> <dt class="sig sig-object py" id="sys.pycache_prefix"> +<code>sys.pycache_prefix</code> </dt> <dd> +<p>If this is set (not <code>None</code>), Python will write bytecode-cache <code>.pyc</code> files to (and read them from) a parallel directory tree rooted at this directory, rather than from <code>__pycache__</code> directories in the source code tree. Any <code>__pycache__</code> directories in the source code tree will be ignored and new <code>.pyc</code> files written within the pycache prefix. Thus if you use <a class="reference internal" href="compileall#module-compileall" title="compileall: Tools for byte-compiling all Python source files in a directory tree."><code>compileall</code></a> as a pre-build step, you must ensure you run it with the same pycache prefix (if any) that you will use at runtime.</p> <p>A relative path is interpreted relative to the current working directory.</p> <p>This value is initially set based on the value of the <a class="reference internal" href="../using/cmdline#cmdoption-X"><code>-X</code></a> <code>pycache_prefix=PATH</code> command-line option or the <span class="target" id="index-7"></span><a class="reference internal" href="../using/cmdline#envvar-PYTHONPYCACHEPREFIX"><code>PYTHONPYCACHEPREFIX</code></a> environment variable (command-line takes precedence). If neither are set, it is <code>None</code>.</p> <div class="versionadded"> <p><span class="versionmodified added">New in version 3.8.</span></p> </div> </dd> +</dl> <dl class="py function"> <dt class="sig sig-object py" id="sys.excepthook"> +<code>sys.excepthook(type, value, traceback)</code> </dt> <dd> +<p>This function prints out a given traceback and exception to <code>sys.stderr</code>.</p> <p>When an exception other than <a class="reference internal" href="exceptions#SystemExit" title="SystemExit"><code>SystemExit</code></a> is raised and uncaught, the interpreter calls <code>sys.excepthook</code> with three arguments, the exception class, exception instance, and a traceback object. In an interactive session this happens just before control is returned to the prompt; in a Python program this happens just before the program exits. The handling of such top-level exceptions can be customized by assigning another three-argument function to <code>sys.excepthook</code>.</p> <p class="audit-hook"></p> +<p>Raise an auditing event <code>sys.excepthook</code> with arguments <code>hook</code>, <code>type</code>, <code>value</code>, <code>traceback</code> when an uncaught exception occurs. If no hook has been set, <code>hook</code> may be <code>None</code>. If any hook raises an exception derived from <a class="reference internal" href="exceptions#RuntimeError" title="RuntimeError"><code>RuntimeError</code></a> the call to the hook will be suppressed. Otherwise, the audit hook exception will be reported as unraisable and <code>sys.excepthook</code> will be called.</p> <div class="admonition seealso"> <p class="admonition-title">See also</p> <p>The <a class="reference internal" href="#sys.unraisablehook" title="sys.unraisablehook"><code>sys.unraisablehook()</code></a> function handles unraisable exceptions and the <a class="reference internal" href="threading#threading.excepthook" title="threading.excepthook"><code>threading.excepthook()</code></a> function handles exception raised by <a class="reference internal" href="threading#threading.Thread.run" title="threading.Thread.run"><code>threading.Thread.run()</code></a>.</p> </div> </dd> +</dl> <dl class="py data"> <dt class="sig sig-object py" id="sys.__breakpointhook__"> +<code>sys.__breakpointhook__</code> </dt> <dt class="sig sig-object py" id="sys.__displayhook__"> +<code>sys.__displayhook__</code> </dt> <dt class="sig sig-object py" id="sys.__excepthook__"> +<code>sys.__excepthook__</code> </dt> <dt class="sig sig-object py" id="sys.__unraisablehook__"> +<code>sys.__unraisablehook__</code> </dt> <dd> +<p>These objects contain the original values of <code>breakpointhook</code>, <code>displayhook</code>, <code>excepthook</code>, and <code>unraisablehook</code> at the start of the program. They are saved so that <code>breakpointhook</code>, <code>displayhook</code> and <code>excepthook</code>, <code>unraisablehook</code> can be restored in case they happen to get replaced with broken or alternative objects.</p> <div class="versionadded"> <p><span class="versionmodified added">New in version 3.7: </span>__breakpointhook__</p> </div> <div class="versionadded"> <p><span class="versionmodified added">New in version 3.8: </span>__unraisablehook__</p> </div> </dd> +</dl> <dl class="py function"> <dt class="sig sig-object py" id="sys.exception"> +<code>sys.exception()</code> </dt> <dd> +<p>This function, when called while an exception handler is executing (such as an <code>except</code> or <code>except*</code> clause), returns the exception instance that was caught by this handler. When exception handlers are nested within one another, only the exception handled by the innermost handler is accessible.</p> <p>If no exception handler is executing, this function returns <code>None</code>.</p> <div class="versionadded"> <p><span class="versionmodified added">New in version 3.11.</span></p> </div> </dd> +</dl> <dl class="py function"> <dt class="sig sig-object py" id="sys.exc_info"> +<code>sys.exc_info()</code> </dt> <dd> +<p>This function returns the old-style representation of the handled exception. If an exception <code>e</code> is currently handled (so <a class="reference internal" href="#sys.exception" title="sys.exception"><code>exception()</code></a> would return <code>e</code>), <a class="reference internal" href="#sys.exc_info" title="sys.exc_info"><code>exc_info()</code></a> returns the tuple <code>(type(e), e, e.__traceback__)</code>. That is, a tuple containing the type of the exception (a subclass of <a class="reference internal" href="exceptions#BaseException" title="BaseException"><code>BaseException</code></a>), the exception itself, and a <a class="reference internal" href="../reference/datamodel#traceback-objects"><span class="std std-ref">traceback object</span></a> which typically encapsulates the call stack at the point where the exception last occurred.</p> <p id="index-8">If no exception is being handled anywhere on the stack, this function return a tuple containing three <code>None</code> values.</p> <div class="versionchanged"> <p><span class="versionmodified changed">Changed in version 3.11: </span>The <code>type</code> and <code>traceback</code> fields are now derived from the <code>value</code> (the exception instance), so when an exception is modified while it is being handled, the changes are reflected in the results of subsequent calls to <a class="reference internal" href="#sys.exc_info" title="sys.exc_info"><code>exc_info()</code></a>.</p> </div> </dd> +</dl> <dl class="py data"> <dt class="sig sig-object py" id="sys.exec_prefix"> +<code>sys.exec_prefix</code> </dt> <dd> +<p>A string giving the site-specific directory prefix where the platform-dependent Python files are installed; by default, this is also <code>'/usr/local'</code>. This can be set at build time with the <code>--exec-prefix</code> argument to the <strong class="program">configure</strong> script. Specifically, all configuration files (e.g. the <code>pyconfig.h</code> header file) are installed in the directory <code><em>exec_prefix</em>/lib/python<em>X.Y</em>/config</code>, and shared library modules are installed in <code><em>exec_prefix</em>/lib/python<em>X.Y</em>/lib-dynload</code>, where <em>X.Y</em> is the version number of Python, for example <code>3.2</code>.</p> <div class="admonition note"> <p class="admonition-title">Note</p> <p>If a <a class="reference internal" href="venv#venv-def"><span class="std std-ref">virtual environment</span></a> is in effect, this value will be changed in <code>site.py</code> to point to the virtual environment. The value for the Python installation will still be available, via <a class="reference internal" href="#sys.base_exec_prefix" title="sys.base_exec_prefix"><code>base_exec_prefix</code></a>.</p> </div> </dd> +</dl> <dl class="py data"> <dt class="sig sig-object py" id="sys.executable"> +<code>sys.executable</code> </dt> <dd> +<p>A string giving the absolute path of the executable binary for the Python interpreter, on systems where this makes sense. If Python is unable to retrieve the real path to its executable, <a class="reference internal" href="#sys.executable" title="sys.executable"><code>sys.executable</code></a> will be an empty string or <code>None</code>.</p> </dd> +</dl> <dl class="py function"> <dt class="sig sig-object py" id="sys.exit"> +<code>sys.exit([arg])</code> </dt> <dd> +<p>Raise a <a class="reference internal" href="exceptions#SystemExit" title="SystemExit"><code>SystemExit</code></a> exception, signaling an intention to exit the interpreter.</p> <p>The optional argument <em>arg</em> can be an integer giving the exit status (defaulting to zero), or another type of object. If it is an integer, zero is considered “successful termination” and any nonzero value is considered “abnormal termination” by shells and the like. Most systems require it to be in the range 0–127, and produce undefined results otherwise. Some systems have a convention for assigning specific meanings to specific exit codes, but these are generally underdeveloped; Unix programs generally use 2 for command line syntax errors and 1 for all other kind of errors. If another type of object is passed, <code>None</code> is equivalent to passing zero, and any other object is printed to <a class="reference internal" href="#sys.stderr" title="sys.stderr"><code>stderr</code></a> and results in an exit code of 1. In particular, <code>sys.exit("some error message")</code> is a quick way to exit a program when an error occurs.</p> <p>Since <a class="reference internal" href="constants#exit" title="exit"><code>exit()</code></a> ultimately “only” raises an exception, it will only exit the process when called from the main thread, and the exception is not intercepted. Cleanup actions specified by finally clauses of <a class="reference internal" href="../reference/compound_stmts#try"><code>try</code></a> statements are honored, and it is possible to intercept the exit attempt at an outer level.</p> <div class="versionchanged"> <p><span class="versionmodified changed">Changed in version 3.6: </span>If an error occurs in the cleanup after the Python interpreter has caught <a class="reference internal" href="exceptions#SystemExit" title="SystemExit"><code>SystemExit</code></a> (such as an error flushing buffered data in the standard streams), the exit status is changed to 120.</p> </div> </dd> +</dl> <dl class="py data"> <dt class="sig sig-object py" id="sys.flags"> +<code>sys.flags</code> </dt> <dd> +<p>The <a class="reference internal" href="../glossary#term-named-tuple"><span class="xref std std-term">named tuple</span></a> <em>flags</em> exposes the status of command line flags. The attributes are read only.</p> <table class="docutils align-default"> <tr> +<td> +<dl class="py attribute"> <dt class="sig sig-object py" id="sys.flags.debug"> +<code>flags.debug</code> </dt> <dd></dd> +</dl> </td> <td><p><a class="reference internal" href="../using/cmdline#cmdoption-d"><code>-d</code></a></p></td> </tr> <tr> +<td> +<dl class="py attribute"> <dt class="sig sig-object py" id="sys.flags.inspect"> +<code>flags.inspect</code> </dt> <dd></dd> +</dl> </td> <td><p><a class="reference internal" href="../using/cmdline#cmdoption-i"><code>-i</code></a></p></td> </tr> <tr> +<td> +<dl class="py attribute"> <dt class="sig sig-object py" id="sys.flags.interactive"> +<code>flags.interactive</code> </dt> <dd></dd> +</dl> </td> <td><p><a class="reference internal" href="../using/cmdline#cmdoption-i"><code>-i</code></a></p></td> </tr> <tr> +<td> +<dl class="py attribute"> <dt class="sig sig-object py" id="sys.flags.isolated"> +<code>flags.isolated</code> </dt> <dd></dd> +</dl> </td> <td><p><a class="reference internal" href="../using/cmdline#cmdoption-I"><code>-I</code></a></p></td> </tr> <tr> +<td> +<dl class="py attribute"> <dt class="sig sig-object py" id="sys.flags.optimize"> +<code>flags.optimize</code> </dt> <dd></dd> +</dl> </td> <td><p><a class="reference internal" href="../using/cmdline#cmdoption-O"><code>-O</code></a> or <a class="reference internal" href="../using/cmdline#cmdoption-OO"><code>-OO</code></a></p></td> </tr> <tr> +<td> +<dl class="py attribute"> <dt class="sig sig-object py" id="sys.flags.dont_write_bytecode"> +<code>flags.dont_write_bytecode</code> </dt> <dd></dd> +</dl> </td> <td><p><a class="reference internal" href="../using/cmdline#cmdoption-B"><code>-B</code></a></p></td> </tr> <tr> +<td> +<dl class="py attribute"> <dt class="sig sig-object py" id="sys.flags.no_user_site"> +<code>flags.no_user_site</code> </dt> <dd></dd> +</dl> </td> <td><p><a class="reference internal" href="../using/cmdline#cmdoption-s"><code>-s</code></a></p></td> </tr> <tr> +<td> +<dl class="py attribute"> <dt class="sig sig-object py" id="sys.flags.no_site"> +<code>flags.no_site</code> </dt> <dd></dd> +</dl> </td> <td><p><a class="reference internal" href="../using/cmdline#cmdoption-S"><code>-S</code></a></p></td> </tr> <tr> +<td> +<dl class="py attribute"> <dt class="sig sig-object py" id="sys.flags.ignore_environment"> +<code>flags.ignore_environment</code> </dt> <dd></dd> +</dl> </td> <td><p><a class="reference internal" href="../using/cmdline#cmdoption-E"><code>-E</code></a></p></td> </tr> <tr> +<td> +<dl class="py attribute"> <dt class="sig sig-object py" id="sys.flags.verbose"> +<code>flags.verbose</code> </dt> <dd></dd> +</dl> </td> <td><p><a class="reference internal" href="../using/cmdline#cmdoption-1"><code>-v</code></a></p></td> </tr> <tr> +<td> +<dl class="py attribute"> <dt class="sig sig-object py" id="sys.flags.bytes_warning"> +<code>flags.bytes_warning</code> </dt> <dd></dd> +</dl> </td> <td><p><a class="reference internal" href="../using/cmdline#cmdoption-b"><code>-b</code></a></p></td> </tr> <tr> +<td> +<dl class="py attribute"> <dt class="sig sig-object py" id="sys.flags.quiet"> +<code>flags.quiet</code> </dt> <dd></dd> +</dl> </td> <td><p><a class="reference internal" href="../using/cmdline#cmdoption-q"><code>-q</code></a></p></td> </tr> <tr> +<td> +<dl class="py attribute"> <dt class="sig sig-object py" id="sys.flags.hash_randomization"> +<code>flags.hash_randomization</code> </dt> <dd></dd> +</dl> </td> <td><p><a class="reference internal" href="../using/cmdline#cmdoption-R"><code>-R</code></a></p></td> </tr> <tr> +<td> +<dl class="py attribute"> <dt class="sig sig-object py" id="sys.flags.dev_mode"> +<code>flags.dev_mode</code> </dt> <dd></dd> +</dl> </td> <td><p><a class="reference internal" href="../using/cmdline#cmdoption-X"><code>-X dev</code></a> (<a class="reference internal" href="devmode#devmode"><span class="std std-ref">Python Development Mode</span></a>)</p></td> </tr> <tr> +<td> +<dl class="py attribute"> <dt class="sig sig-object py" id="sys.flags.utf8_mode"> +<code>flags.utf8_mode</code> </dt> <dd></dd> +</dl> </td> <td><p><a class="reference internal" href="../using/cmdline#cmdoption-X"><code>-X utf8</code></a></p></td> </tr> <tr> +<td> +<dl class="py attribute"> <dt class="sig sig-object py" id="sys.flags.safe_path"> +<code>flags.safe_path</code> </dt> <dd></dd> +</dl> </td> <td><p><a class="reference internal" href="../using/cmdline#cmdoption-P"><code>-P</code></a></p></td> </tr> <tr> +<td> +<dl class="py attribute"> <dt class="sig sig-object py" id="sys.flags.int_max_str_digits"> +<code>flags.int_max_str_digits</code> </dt> <dd></dd> +</dl> </td> <td><p><a class="reference internal" href="../using/cmdline#cmdoption-X"><code>-X int_max_str_digits</code></a> (<a class="reference internal" href="stdtypes#int-max-str-digits"><span class="std std-ref">integer string conversion length limitation</span></a>)</p></td> </tr> <tr> +<td> +<dl class="py attribute"> <dt class="sig sig-object py" id="sys.flags.warn_default_encoding"> +<code>flags.warn_default_encoding</code> </dt> <dd></dd> +</dl> </td> <td><p><a class="reference internal" href="../using/cmdline#cmdoption-X"><code>-X warn_default_encoding</code></a></p></td> </tr> </table> <div class="versionchanged"> <p><span class="versionmodified changed">Changed in version 3.2: </span>Added <code>quiet</code> attribute for the new <a class="reference internal" href="../using/cmdline#cmdoption-q"><code>-q</code></a> flag.</p> </div> <div class="versionadded"> <p><span class="versionmodified added">New in version 3.2.3: </span>The <code>hash_randomization</code> attribute.</p> </div> <div class="versionchanged"> <p><span class="versionmodified changed">Changed in version 3.3: </span>Removed obsolete <code>division_warning</code> attribute.</p> </div> <div class="versionchanged"> <p><span class="versionmodified changed">Changed in version 3.4: </span>Added <code>isolated</code> attribute for <a class="reference internal" href="../using/cmdline#cmdoption-I"><code>-I</code></a> <code>isolated</code> flag.</p> </div> <div class="versionchanged"> <p><span class="versionmodified changed">Changed in version 3.7: </span>Added the <code>dev_mode</code> attribute for the new <a class="reference internal" href="devmode#devmode"><span class="std std-ref">Python Development Mode</span></a> and the <code>utf8_mode</code> attribute for the new <a class="reference internal" href="../using/cmdline#cmdoption-X"><code>-X</code></a> <code>utf8</code> flag.</p> </div> <div class="versionchanged"> <p><span class="versionmodified changed">Changed in version 3.10: </span>Added <code>warn_default_encoding</code> attribute for <a class="reference internal" href="../using/cmdline#cmdoption-X"><code>-X</code></a> <code>warn_default_encoding</code> flag.</p> </div> <div class="versionchanged"> <p><span class="versionmodified changed">Changed in version 3.11: </span>Added the <code>safe_path</code> attribute for <a class="reference internal" href="../using/cmdline#cmdoption-P"><code>-P</code></a> option.</p> </div> <div class="versionchanged"> <p><span class="versionmodified changed">Changed in version 3.11: </span>Added the <code>int_max_str_digits</code> attribute.</p> </div> </dd> +</dl> <dl class="py data"> <dt class="sig sig-object py" id="sys.float_info"> +<code>sys.float_info</code> </dt> <dd> +<p>A <a class="reference internal" href="../glossary#term-named-tuple"><span class="xref std std-term">named tuple</span></a> holding information about the float type. It contains low level information about the precision and internal representation. The values correspond to the various floating-point constants defined in the standard header file <code>float.h</code> for the ‘C’ programming language; see section 5.2.4.2.2 of the 1999 ISO/IEC C standard <a class="reference internal" href="#c99" id="id1"><span>[C99]</span></a>, ‘Characteristics of floating types’, for details.</p> <table class="docutils align-default" id="id2"> <caption><span class="caption-text">Attributes of the <code>float_info</code> <a class="reference internal" href="../glossary#term-named-tuple"><span class="xref std std-term">named tuple</span></a></span></caption> <thead> <tr> +<th class="head"><p>attribute</p></th> <th class="head"><p>float.h macro</p></th> <th class="head"><p>explanation</p></th> </tr> </thead> <tr> +<td> +<dl class="py attribute"> <dt class="sig sig-object py" id="sys.float_info.epsilon"> +<code>float_info.epsilon</code> </dt> <dd></dd> +</dl> </td> <td><p><code>DBL_EPSILON</code></p></td> <td> +<p>difference between 1.0 and the least value greater than 1.0 that is representable as a float.</p> <p>See also <a class="reference internal" href="math#math.ulp" title="math.ulp"><code>math.ulp()</code></a>.</p> </td> </tr> <tr> +<td> +<dl class="py attribute"> <dt class="sig sig-object py" id="sys.float_info.dig"> +<code>float_info.dig</code> </dt> <dd></dd> +</dl> </td> <td><p><code>DBL_DIG</code></p></td> <td><p>The maximum number of decimal digits that can be faithfully represented in a float; see below.</p></td> </tr> <tr> +<td> +<dl class="py attribute"> <dt class="sig sig-object py" id="sys.float_info.mant_dig"> +<code>float_info.mant_dig</code> </dt> <dd></dd> +</dl> </td> <td><p><code>DBL_MANT_DIG</code></p></td> <td><p>Float precision: the number of base-<code>radix</code> digits in the significand of a float.</p></td> </tr> <tr> +<td> +<dl class="py attribute"> <dt class="sig sig-object py" id="sys.float_info.max"> +<code>float_info.max</code> </dt> <dd></dd> +</dl> </td> <td><p><code>DBL_MAX</code></p></td> <td><p>The maximum representable positive finite float.</p></td> </tr> <tr> +<td> +<dl class="py attribute"> <dt class="sig sig-object py" id="sys.float_info.max_exp"> +<code>float_info.max_exp</code> </dt> <dd></dd> +</dl> </td> <td><p><code>DBL_MAX_EXP</code></p></td> <td><p>The maximum integer <em>e</em> such that <code>radix**(e-1)</code> is a representable finite float.</p></td> </tr> <tr> +<td> +<dl class="py attribute"> <dt class="sig sig-object py" id="sys.float_info.max_10_exp"> +<code>float_info.max_10_exp</code> </dt> <dd></dd> +</dl> </td> <td><p><code>DBL_MAX_10_EXP</code></p></td> <td><p>The maximum integer <em>e</em> such that <code>10**e</code> is in the range of representable finite floats.</p></td> </tr> <tr> +<td> +<dl class="py attribute"> <dt class="sig sig-object py" id="sys.float_info.min"> +<code>float_info.min</code> </dt> <dd></dd> +</dl> </td> <td><p><code>DBL_MIN</code></p></td> <td> +<p>The minimum representable positive <em>normalized</em> float.</p> <p>Use <a class="reference internal" href="math#math.ulp" title="math.ulp"><code>math.ulp(0.0)</code></a> to get the smallest positive <em>denormalized</em> representable float.</p> </td> </tr> <tr> +<td> +<dl class="py attribute"> <dt class="sig sig-object py" id="sys.float_info.min_exp"> +<code>float_info.min_exp</code> </dt> <dd></dd> +</dl> </td> <td><p><code>DBL_MIN_EXP</code></p></td> <td><p>The minimum integer <em>e</em> such that <code>radix**(e-1)</code> is a normalized float.</p></td> </tr> <tr> +<td> +<dl class="py attribute"> <dt class="sig sig-object py" id="sys.float_info.min_10_exp"> +<code>float_info.min_10_exp</code> </dt> <dd></dd> +</dl> </td> <td><p><code>DBL_MIN_10_EXP</code></p></td> <td><p>The minimum integer <em>e</em> such that <code>10**e</code> is a normalized float.</p></td> </tr> <tr> +<td> +<dl class="py attribute"> <dt class="sig sig-object py" id="sys.float_info.radix"> +<code>float_info.radix</code> </dt> <dd></dd> +</dl> </td> <td><p><code>FLT_RADIX</code></p></td> <td><p>The radix of exponent representation.</p></td> </tr> <tr> +<td> +<dl class="py attribute"> <dt class="sig sig-object py" id="sys.float_info.rounds"> +<code>float_info.rounds</code> </dt> <dd></dd> +</dl> </td> <td><p><code>FLT_ROUNDS</code></p></td> <td> +<p>An integer representing the rounding mode for floating-point arithmetic. This reflects the value of the system <code>FLT_ROUNDS</code> macro at interpreter startup time:</p> <ul class="simple"> <li> +<code>-1</code>: indeterminable</li> <li> +<code>0</code>: toward zero</li> <li> +<code>1</code>: to nearest</li> <li> +<code>2</code>: toward positive infinity</li> <li> +<code>3</code>: toward negative infinity</li> </ul> <p>All other values for <code>FLT_ROUNDS</code> characterize implementation-defined rounding behavior.</p> </td> </tr> </table> <p>The attribute <a class="reference internal" href="#sys.float_info.dig" title="sys.float_info.dig"><code>sys.float_info.dig</code></a> needs further explanation. If <code>s</code> is any string representing a decimal number with at most <code>sys.float_info.dig</code> significant digits, then converting <code>s</code> to a float and back again will recover a string representing the same decimal value:</p> <pre data-language="python">>>> import sys +>>> sys.float_info.dig +15 +>>> s = '3.14159265358979' # decimal string with 15 significant digits +>>> format(float(s), '.15g') # convert to float and back -> same value +'3.14159265358979' +</pre> <p>But for strings with more than <a class="reference internal" href="#sys.float_info.dig" title="sys.float_info.dig"><code>sys.float_info.dig</code></a> significant digits, this isn’t always true:</p> <pre data-language="python">>>> s = '9876543211234567' # 16 significant digits is too many! +>>> format(float(s), '.16g') # conversion changes value +'9876543211234568' +</pre> </dd> +</dl> <dl class="py data"> <dt class="sig sig-object py" id="sys.float_repr_style"> +<code>sys.float_repr_style</code> </dt> <dd> +<p>A string indicating how the <a class="reference internal" href="functions#repr" title="repr"><code>repr()</code></a> function behaves for floats. If the string has value <code>'short'</code> then for a finite float <code>x</code>, <code>repr(x)</code> aims to produce a short string with the property that <code>float(repr(x)) == x</code>. This is the usual behaviour in Python 3.1 and later. Otherwise, <code>float_repr_style</code> has value <code>'legacy'</code> and <code>repr(x)</code> behaves in the same way as it did in versions of Python prior to 3.1.</p> <div class="versionadded"> <p><span class="versionmodified added">New in version 3.1.</span></p> </div> </dd> +</dl> <dl class="py function"> <dt class="sig sig-object py" id="sys.getallocatedblocks"> +<code>sys.getallocatedblocks()</code> </dt> <dd> +<p>Return the number of memory blocks currently allocated by the interpreter, regardless of their size. This function is mainly useful for tracking and debugging memory leaks. Because of the interpreter’s internal caches, the result can vary from call to call; you may have to call <a class="reference internal" href="#sys._clear_type_cache" title="sys._clear_type_cache"><code>_clear_type_cache()</code></a> and <a class="reference internal" href="gc#gc.collect" title="gc.collect"><code>gc.collect()</code></a> to get more predictable results.</p> <p>If a Python build or implementation cannot reasonably compute this information, <a class="reference internal" href="#sys.getallocatedblocks" title="sys.getallocatedblocks"><code>getallocatedblocks()</code></a> is allowed to return 0 instead.</p> <div class="versionadded"> <p><span class="versionmodified added">New in version 3.4.</span></p> </div> </dd> +</dl> <dl class="py function"> <dt class="sig sig-object py" id="sys.getunicodeinternedsize"> +<code>sys.getunicodeinternedsize()</code> </dt> <dd> +<p>Return the number of unicode objects that have been interned.</p> <div class="versionadded"> <p><span class="versionmodified added">New in version 3.12.</span></p> </div> </dd> +</dl> <dl class="py function"> <dt class="sig sig-object py" id="sys.getandroidapilevel"> +<code>sys.getandroidapilevel()</code> </dt> <dd> +<p>Return the build time API version of Android as an integer.</p> <div class="availability docutils container"> <p><a class="reference internal" href="https://docs.python.org/3.12/library/intro.html#availability"><span class="std std-ref">Availability</span></a>: Android.</p> </div> <div class="versionadded"> <p><span class="versionmodified added">New in version 3.7.</span></p> </div> </dd> +</dl> <dl class="py function"> <dt class="sig sig-object py" id="sys.getdefaultencoding"> +<code>sys.getdefaultencoding()</code> </dt> <dd> +<p>Return the name of the current default string encoding used by the Unicode implementation.</p> </dd> +</dl> <dl class="py function"> <dt class="sig sig-object py" id="sys.getdlopenflags"> +<code>sys.getdlopenflags()</code> </dt> <dd> +<p>Return the current value of the flags that are used for <code>dlopen()</code> calls. Symbolic names for the flag values can be found in the <a class="reference internal" href="os#module-os" title="os: Miscellaneous operating system interfaces."><code>os</code></a> module (<code>RTLD_<em>xxx</em></code> constants, e.g. <a class="reference internal" href="os#os.RTLD_LAZY" title="os.RTLD_LAZY"><code>os.RTLD_LAZY</code></a>).</p> <div class="availability docutils container"> <p><a class="reference internal" href="https://docs.python.org/3.12/library/intro.html#availability"><span class="std std-ref">Availability</span></a>: Unix.</p> </div> </dd> +</dl> <dl class="py function"> <dt class="sig sig-object py" id="sys.getfilesystemencoding"> +<code>sys.getfilesystemencoding()</code> </dt> <dd> +<p>Get the <a class="reference internal" href="../glossary#term-filesystem-encoding-and-error-handler"><span class="xref std std-term">filesystem encoding</span></a>: the encoding used with the <a class="reference internal" href="../glossary#term-filesystem-encoding-and-error-handler"><span class="xref std std-term">filesystem error handler</span></a> to convert between Unicode filenames and bytes filenames. The filesystem error handler is returned from <a class="reference internal" href="#sys.getfilesystemencodeerrors" title="sys.getfilesystemencodeerrors"><code>getfilesystemencodeerrors()</code></a>.</p> <p>For best compatibility, str should be used for filenames in all cases, although representing filenames as bytes is also supported. Functions accepting or returning filenames should support either str or bytes and internally convert to the system’s preferred representation.</p> <p><a class="reference internal" href="os#os.fsencode" title="os.fsencode"><code>os.fsencode()</code></a> and <a class="reference internal" href="os#os.fsdecode" title="os.fsdecode"><code>os.fsdecode()</code></a> should be used to ensure that the correct encoding and errors mode are used.</p> <p>The <a class="reference internal" href="../glossary#term-filesystem-encoding-and-error-handler"><span class="xref std std-term">filesystem encoding and error handler</span></a> are configured at Python startup by the <a class="reference internal" href="../c-api/init_config#c.PyConfig_Read" title="PyConfig_Read"><code>PyConfig_Read()</code></a> function: see <a class="reference internal" href="../c-api/init_config#c.PyConfig.filesystem_encoding" title="PyConfig.filesystem_encoding"><code>filesystem_encoding</code></a> and <a class="reference internal" href="../c-api/init_config#c.PyConfig.filesystem_errors" title="PyConfig.filesystem_errors"><code>filesystem_errors</code></a> members of <a class="reference internal" href="../c-api/init_config#c.PyConfig" title="PyConfig"><code>PyConfig</code></a>.</p> <div class="versionchanged"> <p><span class="versionmodified changed">Changed in version 3.2: </span><a class="reference internal" href="#sys.getfilesystemencoding" title="sys.getfilesystemencoding"><code>getfilesystemencoding()</code></a> result cannot be <code>None</code> anymore.</p> </div> <div class="versionchanged"> <p><span class="versionmodified changed">Changed in version 3.6: </span>Windows is no longer guaranteed to return <code>'mbcs'</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> and <a class="reference internal" href="#sys._enablelegacywindowsfsencoding" title="sys._enablelegacywindowsfsencoding"><code>_enablelegacywindowsfsencoding()</code></a> for more information.</p> </div> <div class="versionchanged"> <p><span class="versionmodified changed">Changed in version 3.7: </span>Return <code>'utf-8'</code> if the <a class="reference internal" href="os#utf8-mode"><span class="std std-ref">Python UTF-8 Mode</span></a> is enabled.</p> </div> </dd> +</dl> <dl class="py function"> <dt class="sig sig-object py" id="sys.getfilesystemencodeerrors"> +<code>sys.getfilesystemencodeerrors()</code> </dt> <dd> +<p>Get the <a class="reference internal" href="../glossary#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#term-filesystem-encoding-and-error-handler"><span class="xref std std-term">filesystem encoding</span></a> to convert between Unicode filenames and bytes filenames. The filesystem encoding is returned from <a class="reference internal" href="#sys.getfilesystemencoding" title="sys.getfilesystemencoding"><code>getfilesystemencoding()</code></a>.</p> <p><a class="reference internal" href="os#os.fsencode" title="os.fsencode"><code>os.fsencode()</code></a> and <a class="reference internal" href="os#os.fsdecode" title="os.fsdecode"><code>os.fsdecode()</code></a> should be used to ensure that the correct encoding and errors mode are used.</p> <p>The <a class="reference internal" href="../glossary#term-filesystem-encoding-and-error-handler"><span class="xref std std-term">filesystem encoding and error handler</span></a> are configured at Python startup by the <a class="reference internal" href="../c-api/init_config#c.PyConfig_Read" title="PyConfig_Read"><code>PyConfig_Read()</code></a> function: see <a class="reference internal" href="../c-api/init_config#c.PyConfig.filesystem_encoding" title="PyConfig.filesystem_encoding"><code>filesystem_encoding</code></a> and <a class="reference internal" href="../c-api/init_config#c.PyConfig.filesystem_errors" title="PyConfig.filesystem_errors"><code>filesystem_errors</code></a> members of <a class="reference internal" href="../c-api/init_config#c.PyConfig" title="PyConfig"><code>PyConfig</code></a>.</p> <div class="versionadded"> <p><span class="versionmodified added">New in version 3.6.</span></p> </div> </dd> +</dl> <dl class="py function"> <dt class="sig sig-object py" id="sys.get_int_max_str_digits"> +<code>sys.get_int_max_str_digits()</code> </dt> <dd> +<p>Returns the current value for the <a class="reference internal" href="stdtypes#int-max-str-digits"><span class="std std-ref">integer string conversion length limitation</span></a>. See also <a class="reference internal" href="#sys.set_int_max_str_digits" title="sys.set_int_max_str_digits"><code>set_int_max_str_digits()</code></a>.</p> <div class="versionadded"> <p><span class="versionmodified added">New in version 3.11.</span></p> </div> </dd> +</dl> <dl class="py function"> <dt class="sig sig-object py" id="sys.getrefcount"> +<code>sys.getrefcount(object)</code> </dt> <dd> +<p>Return the reference count of the <em>object</em>. The count returned is generally one higher than you might expect, because it includes the (temporary) reference as an argument to <a class="reference internal" href="#sys.getrefcount" title="sys.getrefcount"><code>getrefcount()</code></a>.</p> <p>Note that the returned value may not actually reflect how many references to the object are actually held. For example, some objects are “immortal” and have a very high refcount that does not reflect the actual number of references. Consequently, do not rely on the returned value to be accurate, other than a value of 0 or 1.</p> <div class="versionchanged"> <p><span class="versionmodified changed">Changed in version 3.12: </span>Immortal objects have very large refcounts that do not match the actual number of references to the object.</p> </div> </dd> +</dl> <dl class="py function"> <dt class="sig sig-object py" id="sys.getrecursionlimit"> +<code>sys.getrecursionlimit()</code> </dt> <dd> +<p>Return the current value of the recursion limit, the maximum depth of the Python interpreter stack. This limit prevents infinite recursion from causing an overflow of the C stack and crashing Python. It can be set by <a class="reference internal" href="#sys.setrecursionlimit" title="sys.setrecursionlimit"><code>setrecursionlimit()</code></a>.</p> </dd> +</dl> <dl class="py function"> <dt class="sig sig-object py" id="sys.getsizeof"> +<code>sys.getsizeof(object[, default])</code> </dt> <dd> +<p>Return the size of an object in bytes. The object can be any type of object. All built-in objects will return correct results, but this does not have to hold true for third-party extensions as it is implementation specific.</p> <p>Only the memory consumption directly attributed to the object is accounted for, not the memory consumption of objects it refers to.</p> <p>If given, <em>default</em> will be returned if the object does not provide means to retrieve the size. Otherwise a <a class="reference internal" href="exceptions#TypeError" title="TypeError"><code>TypeError</code></a> will be raised.</p> <p><a class="reference internal" href="#sys.getsizeof" title="sys.getsizeof"><code>getsizeof()</code></a> calls the object’s <code>__sizeof__</code> method and adds an additional garbage collector overhead if the object is managed by the garbage collector.</p> <p>See <a class="reference external" href="https://code.activestate.com/recipes/577504/">recursive sizeof recipe</a> for an example of using <a class="reference internal" href="#sys.getsizeof" title="sys.getsizeof"><code>getsizeof()</code></a> recursively to find the size of containers and all their contents.</p> </dd> +</dl> <dl class="py function"> <dt class="sig sig-object py" id="sys.getswitchinterval"> +<code>sys.getswitchinterval()</code> </dt> <dd> +<p>Return the interpreter’s “thread switch interval”; see <a class="reference internal" href="#sys.setswitchinterval" title="sys.setswitchinterval"><code>setswitchinterval()</code></a>.</p> <div class="versionadded"> <p><span class="versionmodified added">New in version 3.2.</span></p> </div> </dd> +</dl> <dl class="py function"> <dt class="sig sig-object py" id="sys._getframe"> +<code>sys._getframe([depth])</code> </dt> <dd> +<p>Return a frame object from the call stack. If optional integer <em>depth</em> is given, return the frame object that many calls below the top of the stack. If that is deeper than the call stack, <a class="reference internal" href="exceptions#ValueError" title="ValueError"><code>ValueError</code></a> is raised. The default for <em>depth</em> is zero, returning the frame at the top of the call stack.</p> <p class="audit-hook">Raises an <a class="reference internal" href="#auditing"><span class="std std-ref">auditing event</span></a> <code>sys._getframe</code> with argument <code>frame</code>.</p> <div class="impl-detail compound"> <p><strong>CPython implementation detail:</strong> This function should be used for internal and specialized purposes only. It is not guaranteed to exist in all implementations of Python.</p> </div> </dd> +</dl> <dl class="py function"> <dt class="sig sig-object py" id="sys._getframemodulename"> +<code>sys._getframemodulename([depth])</code> </dt> <dd> +<p>Return the name of a module from the call stack. If optional integer <em>depth</em> is given, return the module that many calls below the top of the stack. If that is deeper than the call stack, or if the module is unidentifiable, <code>None</code> is returned. The default for <em>depth</em> is zero, returning the module at the top of the call stack.</p> <p class="audit-hook">Raises an <a class="reference internal" href="#auditing"><span class="std std-ref">auditing event</span></a> <code>sys._getframemodulename</code> with argument <code>depth</code>.</p> <div class="impl-detail compound"> <p><strong>CPython implementation detail:</strong> This function should be used for internal and specialized purposes only. It is not guaranteed to exist in all implementations of Python.</p> </div> </dd> +</dl> <dl class="py function"> <dt class="sig sig-object py" id="sys.getprofile"> +<code>sys.getprofile()</code> </dt> <dd> +<p id="index-10">Get the profiler function as set by <a class="reference internal" href="#sys.setprofile" title="sys.setprofile"><code>setprofile()</code></a>.</p> </dd> +</dl> <dl class="py function"> <dt class="sig sig-object py" id="sys.gettrace"> +<code>sys.gettrace()</code> </dt> <dd> +<p id="index-11">Get the trace function as set by <a class="reference internal" href="#sys.settrace" title="sys.settrace"><code>settrace()</code></a>.</p> <div class="impl-detail compound"> <p><strong>CPython implementation detail:</strong> The <a class="reference internal" href="#sys.gettrace" title="sys.gettrace"><code>gettrace()</code></a> function is intended only for implementing debuggers, profilers, coverage tools and the like. Its behavior is part of the implementation platform, rather than part of the language definition, and thus may not be available in all Python implementations.</p> </div> </dd> +</dl> <dl class="py function"> <dt class="sig sig-object py" id="sys.getwindowsversion"> +<code>sys.getwindowsversion()</code> </dt> <dd> +<p>Return a named tuple describing the Windows version currently running. The named elements are <em>major</em>, <em>minor</em>, <em>build</em>, <em>platform</em>, <em>service_pack</em>, <em>service_pack_minor</em>, <em>service_pack_major</em>, <em>suite_mask</em>, <em>product_type</em> and <em>platform_version</em>. <em>service_pack</em> contains a string, <em>platform_version</em> a 3-tuple and all other values are integers. The components can also be accessed by name, so <code>sys.getwindowsversion()[0]</code> is equivalent to <code>sys.getwindowsversion().major</code>. For compatibility with prior versions, only the first 5 elements are retrievable by indexing.</p> <p><em>platform</em> will be <code>2</code> (VER_PLATFORM_WIN32_NT).</p> <p><em>product_type</em> may be one of the following values:</p> <table class="docutils align-default"> <thead> <tr> +<th class="head"><p>Constant</p></th> <th class="head"><p>Meaning</p></th> </tr> </thead> <tr> +<td><p><code>1</code> (VER_NT_WORKSTATION)</p></td> <td><p>The system is a workstation.</p></td> </tr> <tr> +<td><p><code>2</code> (VER_NT_DOMAIN_CONTROLLER)</p></td> <td><p>The system is a domain controller.</p></td> </tr> <tr> +<td><p><code>3</code> (VER_NT_SERVER)</p></td> <td><p>The system is a server, but not a domain controller.</p></td> </tr> </table> <p>This function wraps the Win32 <code>GetVersionEx()</code> function; see the Microsoft documentation on <code>OSVERSIONINFOEX()</code> for more information about these fields.</p> <p><em>platform_version</em> returns the major version, minor version and build number of the current operating system, rather than the version that is being emulated for the process. It is intended for use in logging rather than for feature detection.</p> <div class="admonition note"> <p class="admonition-title">Note</p> <p><em>platform_version</em> derives the version from kernel32.dll which can be of a different version than the OS version. Please use <a class="reference internal" href="platform#module-platform" title="platform: Retrieves as much platform identifying data as possible."><code>platform</code></a> module for achieving accurate OS version.</p> </div> <div class="availability docutils container"> <p><a class="reference internal" href="https://docs.python.org/3.12/library/intro.html#availability"><span class="std std-ref">Availability</span></a>: Windows.</p> </div> <div class="versionchanged"> <p><span class="versionmodified changed">Changed in version 3.2: </span>Changed to a named tuple and added <em>service_pack_minor</em>, <em>service_pack_major</em>, <em>suite_mask</em>, and <em>product_type</em>.</p> </div> <div class="versionchanged"> <p><span class="versionmodified changed">Changed in version 3.6: </span>Added <em>platform_version</em></p> </div> </dd> +</dl> <dl class="py function"> <dt class="sig sig-object py" id="sys.get_asyncgen_hooks"> +<code>sys.get_asyncgen_hooks()</code> </dt> <dd> +<p>Returns an <em>asyncgen_hooks</em> object, which is similar to a <a class="reference internal" href="collections#collections.namedtuple" title="collections.namedtuple"><code>namedtuple</code></a> of the form <code>(firstiter, finalizer)</code>, where <em>firstiter</em> and <em>finalizer</em> are expected to be either <code>None</code> or functions which take an <a class="reference internal" href="../glossary#term-asynchronous-generator-iterator"><span class="xref std std-term">asynchronous generator iterator</span></a> as an argument, and are used to schedule finalization of an asynchronous generator by an event loop.</p> <div class="versionadded"> <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> </div> <div class="admonition note"> <p class="admonition-title">Note</p> <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> for details.)</p> </div> </dd> +</dl> <dl class="py function"> <dt class="sig sig-object py" id="sys.get_coroutine_origin_tracking_depth"> +<code>sys.get_coroutine_origin_tracking_depth()</code> </dt> <dd> +<p>Get the current coroutine origin tracking depth, as set by <a class="reference internal" href="#sys.set_coroutine_origin_tracking_depth" title="sys.set_coroutine_origin_tracking_depth"><code>set_coroutine_origin_tracking_depth()</code></a>.</p> <div class="versionadded"> <p><span class="versionmodified added">New in version 3.7.</span></p> </div> <div class="admonition note"> <p class="admonition-title">Note</p> <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> for details.) Use it only for debugging purposes.</p> </div> </dd> +</dl> <dl class="py data"> <dt class="sig sig-object py" id="sys.hash_info"> +<code>sys.hash_info</code> </dt> <dd> +<p>A <a class="reference internal" href="../glossary#term-named-tuple"><span class="xref std std-term">named tuple</span></a> giving parameters of the numeric hash implementation. For more details about hashing of numeric types, see <a class="reference internal" href="stdtypes#numeric-hash"><span class="std std-ref">Hashing of numeric types</span></a>.</p> <dl class="py attribute"> <dt class="sig sig-object py" id="sys.hash_info.width"> +<code>hash_info.width</code> </dt> <dd> +<p>The width in bits used for hash values</p> </dd> +</dl> <dl class="py attribute"> <dt class="sig sig-object py" id="sys.hash_info.modulus"> +<code>hash_info.modulus</code> </dt> <dd> +<p>The prime modulus P used for numeric hash scheme</p> </dd> +</dl> <dl class="py attribute"> <dt class="sig sig-object py" id="sys.hash_info.inf"> +<code>hash_info.inf</code> </dt> <dd> +<p>The hash value returned for a positive infinity</p> </dd> +</dl> <dl class="py attribute"> <dt class="sig sig-object py" id="sys.hash_info.nan"> +<code>hash_info.nan</code> </dt> <dd> +<p>(This attribute is no longer used)</p> </dd> +</dl> <dl class="py attribute"> <dt class="sig sig-object py" id="sys.hash_info.imag"> +<code>hash_info.imag</code> </dt> <dd> +<p>The multiplier used for the imaginary part of a complex number</p> </dd> +</dl> <dl class="py attribute"> <dt class="sig sig-object py" id="sys.hash_info.algorithm"> +<code>hash_info.algorithm</code> </dt> <dd> +<p>The name of the algorithm for hashing of str, bytes, and memoryview</p> </dd> +</dl> <dl class="py attribute"> <dt class="sig sig-object py" id="sys.hash_info.hash_bits"> +<code>hash_info.hash_bits</code> </dt> <dd> +<p>The internal output size of the hash algorithm</p> </dd> +</dl> <dl class="py attribute"> <dt class="sig sig-object py" id="sys.hash_info.seed_bits"> +<code>hash_info.seed_bits</code> </dt> <dd> +<p>The size of the seed key of the hash algorithm</p> </dd> +</dl> <div class="versionadded"> <p><span class="versionmodified added">New in version 3.2.</span></p> </div> <div class="versionchanged"> <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> </div> </dd> +</dl> <dl class="py data"> <dt class="sig sig-object py" id="sys.hexversion"> +<code>sys.hexversion</code> </dt> <dd> +<p>The version number encoded as a single integer. This is guaranteed to increase with each version, including proper support for non-production releases. For example, to test that the Python interpreter is at least version 1.5.2, use:</p> <pre data-language="python">if sys.hexversion >= 0x010502F0: + # use some advanced feature + ... +else: + # use an alternative implementation or warn the user + ... +</pre> <p>This is called <code>hexversion</code> since it only really looks meaningful when viewed as the result of passing it to the built-in <a class="reference internal" href="functions#hex" title="hex"><code>hex()</code></a> function. The <a class="reference internal" href="../glossary#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>sys.version_info</code></a> may be used for a more human-friendly encoding of the same information.</p> <p>More details of <code>hexversion</code> can be found at <a class="reference internal" href="../c-api/apiabiversion#apiabiversion"><span class="std std-ref">API and ABI Versioning</span></a>.</p> </dd> +</dl> <dl class="py data"> <dt class="sig sig-object py" id="sys.implementation"> +<code>sys.implementation</code> </dt> <dd> +<p>An object containing information about the implementation of the currently running Python interpreter. The following attributes are required to exist in all Python implementations.</p> <p><em>name</em> is the implementation’s identifier, e.g. <code>'cpython'</code>. The actual string is defined by the Python implementation, but it is guaranteed to be lower case.</p> <p><em>version</em> is a named tuple, in the same format as <a class="reference internal" href="#sys.version_info" title="sys.version_info"><code>sys.version_info</code></a>. It represents the version of the Python <em>implementation</em>. This has a distinct meaning from the specific version of the Python <em>language</em> to which the currently running interpreter conforms, which <code>sys.version_info</code> represents. For example, for PyPy 1.8 <code>sys.implementation.version</code> might be <code>sys.version_info(1, 8, 0, 'final', 0)</code>, whereas <code>sys.version_info</code> would be <code>sys.version_info(2, 7, 2, 'final', 0)</code>. For CPython they are the same value, since it is the reference implementation.</p> <p><em>hexversion</em> is the implementation version in hexadecimal format, like <a class="reference internal" href="#sys.hexversion" title="sys.hexversion"><code>sys.hexversion</code></a>.</p> <p><em>cache_tag</em> is the tag used by the import machinery in the filenames of cached modules. By convention, it would be a composite of the implementation’s name and version, like <code>'cpython-33'</code>. However, a Python implementation may use some other value if appropriate. If <code>cache_tag</code> is set to <code>None</code>, it indicates that module caching should be disabled.</p> <p><a class="reference internal" href="#sys.implementation" title="sys.implementation"><code>sys.implementation</code></a> may contain additional attributes specific to the Python implementation. These non-standard attributes must start with an underscore, and are not described here. Regardless of its contents, <a class="reference internal" href="#sys.implementation" title="sys.implementation"><code>sys.implementation</code></a> will not change during a run of the interpreter, nor between implementation versions. (It may change between Python 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> <div class="versionadded"> <p><span class="versionmodified added">New in version 3.3.</span></p> </div> <div class="admonition note"> <p class="admonition-title">Note</p> <p>The addition of new required attributes must go through the normal PEP 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> </div> </dd> +</dl> <dl class="py data"> <dt class="sig sig-object py" id="sys.int_info"> +<code>sys.int_info</code> </dt> <dd> +<p>A <a class="reference internal" href="../glossary#term-named-tuple"><span class="xref std std-term">named tuple</span></a> that holds information about Python’s internal representation of integers. The attributes are read only.</p> <dl class="py attribute"> <dt class="sig sig-object py" id="sys.int_info.bits_per_digit"> +<code>int_info.bits_per_digit</code> </dt> <dd> +<p>The number of bits held in each digit. Python integers are stored internally in base <code>2**int_info.bits_per_digit</code>.</p> </dd> +</dl> <dl class="py attribute"> <dt class="sig sig-object py" id="sys.int_info.sizeof_digit"> +<code>int_info.sizeof_digit</code> </dt> <dd> +<p>The size in bytes of the C type used to represent a digit.</p> </dd> +</dl> <dl class="py attribute"> <dt class="sig sig-object py" id="sys.int_info.default_max_str_digits"> +<code>int_info.default_max_str_digits</code> </dt> <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>sys.get_int_max_str_digits()</code></a> when it is not otherwise explicitly configured.</p> </dd> +</dl> <dl class="py attribute"> <dt class="sig sig-object py" id="sys.int_info.str_digits_check_threshold"> +<code>int_info.str_digits_check_threshold</code> </dt> <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>sys.set_int_max_str_digits()</code></a>, <span class="target" id="index-17"></span><a class="reference internal" href="../using/cmdline#envvar-PYTHONINTMAXSTRDIGITS"><code>PYTHONINTMAXSTRDIGITS</code></a>, or <a class="reference internal" href="../using/cmdline#cmdoption-X"><code>-X int_max_str_digits</code></a>.</p> </dd> +</dl> <div class="versionadded"> <p><span class="versionmodified added">New in version 3.1.</span></p> </div> <div class="versionchanged"> <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>default_max_str_digits</code></a> and <a class="reference internal" href="#sys.int_info.str_digits_check_threshold" title="sys.int_info.str_digits_check_threshold"><code>str_digits_check_threshold</code></a>.</p> </div> </dd> +</dl> <dl class="py data"> <dt class="sig sig-object py" id="sys.__interactivehook__"> +<code>sys.__interactivehook__</code> </dt> <dd> +<p>When this attribute exists, its value is automatically called (with no arguments) when the interpreter is launched in <a class="reference internal" href="../tutorial/interpreter#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#envvar-PYTHONSTARTUP"><code>PYTHONSTARTUP</code></a> file is read, so that you can set this hook there. The <a class="reference internal" href="site#module-site" title="site: Module responsible for site-specific configuration."><code>site</code></a> module <a class="reference internal" href="site#rlcompleter-config"><span class="std std-ref">sets this</span></a>.</p> <p class="audit-hook"></p> +<p>Raises an <a class="reference internal" href="#auditing"><span class="std std-ref">auditing event</span></a> <code>cpython.run_interactivehook</code> with the hook object as the argument when the hook is called on startup.</p> <div class="versionadded"> <p><span class="versionmodified added">New in version 3.4.</span></p> </div> </dd> +</dl> <dl class="py function"> <dt class="sig sig-object py" id="sys.intern"> +<code>sys.intern(string)</code> </dt> <dd> +<p>Enter <em>string</em> in the table of “interned” strings and return the interned string – which is <em>string</em> itself or a copy. Interning strings is useful to gain a little performance on dictionary lookup – if the keys in a dictionary are interned, and the lookup key is interned, the key comparisons (after hashing) can be done by a pointer compare instead of a string compare. Normally, the names used in Python programs are automatically interned, and the dictionaries used to hold module, class or instance attributes have interned keys.</p> <p>Interned strings are not immortal; you must keep a reference to the return value of <a class="reference internal" href="#sys.intern" title="sys.intern"><code>intern()</code></a> around to benefit from it.</p> </dd> +</dl> <dl class="py function"> <dt class="sig sig-object py" id="sys.is_finalizing"> +<code>sys.is_finalizing()</code> </dt> <dd> +<p>Return <a class="reference internal" href="constants#True" title="True"><code>True</code></a> if the Python interpreter is <a class="reference internal" href="../glossary#term-interpreter-shutdown"><span class="xref std std-term">shutting down</span></a>, <a class="reference internal" href="constants#False" title="False"><code>False</code></a> otherwise.</p> <div class="versionadded"> <p><span class="versionmodified added">New in version 3.5.</span></p> </div> </dd> +</dl> <dl class="py data"> <dt class="sig sig-object py" id="sys.last_exc"> +<code>sys.last_exc</code> </dt> <dd> +<p>This variable is not always defined; it is set to the exception instance when an exception is not handled and the interpreter prints an error message and a stack traceback. Its intended use is to allow an interactive user to import a debugger module and engage in post-mortem debugging without having to re-execute the command that caused the error. (Typical use is <code>import pdb; pdb.pm()</code> to enter the post-mortem debugger; see <a class="reference internal" href="pdb#module-pdb" title="pdb: The Python debugger for interactive interpreters."><code>pdb</code></a> module for more information.)</p> <div class="versionadded"> <p><span class="versionmodified added">New in version 3.12.</span></p> </div> </dd> +</dl> <dl class="py data"> <dt class="sig sig-object py" id="sys.last_type"> +<code>sys.last_type</code> </dt> <dt class="sig sig-object py" id="sys.last_value"> +<code>sys.last_value</code> </dt> <dt class="sig sig-object py" id="sys.last_traceback"> +<code>sys.last_traceback</code> </dt> <dd> +<p>These three variables are deprecated; use <a class="reference internal" href="#sys.last_exc" title="sys.last_exc"><code>sys.last_exc</code></a> instead. They hold the legacy representation of <code>sys.last_exc</code>, as returned from <a class="reference internal" href="#sys.exc_info" title="sys.exc_info"><code>exc_info()</code></a> above.</p> </dd> +</dl> <dl class="py data"> <dt class="sig sig-object py" id="sys.maxsize"> +<code>sys.maxsize</code> </dt> <dd> +<p>An integer giving the maximum value a variable of type <a class="reference internal" href="../c-api/intro#c.Py_ssize_t" title="Py_ssize_t"><code>Py_ssize_t</code></a> can take. It’s usually <code>2**31 - 1</code> on a 32-bit platform and <code>2**63 - 1</code> on a 64-bit platform.</p> </dd> +</dl> <dl class="py data"> <dt class="sig sig-object py" id="sys.maxunicode"> +<code>sys.maxunicode</code> </dt> <dd> +<p>An integer giving the value of the largest Unicode code point, i.e. <code>1114111</code> (<code>0x10FFFF</code> in hexadecimal).</p> <div class="versionchanged"> <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>sys.maxunicode</code> used to be either <code>0xFFFF</code> or <code>0x10FFFF</code>, depending on the configuration option that specified whether Unicode characters were stored as UCS-2 or UCS-4.</p> </div> </dd> +</dl> <dl class="py data"> <dt class="sig sig-object py" id="sys.meta_path"> +<code>sys.meta_path</code> </dt> <dd> +<p>A list of <a class="reference internal" href="../glossary#term-meta-path-finder"><span class="xref std std-term">meta path finder</span></a> objects that have their <a class="reference internal" href="importlib#importlib.abc.MetaPathFinder.find_spec" title="importlib.abc.MetaPathFinder.find_spec"><code>find_spec()</code></a> methods called to see if one of the objects can find the module to be imported. By default, it holds entries that implement Python’s default import semantics. The <a class="reference internal" href="importlib#importlib.abc.MetaPathFinder.find_spec" title="importlib.abc.MetaPathFinder.find_spec"><code>find_spec()</code></a> method is called with at least the absolute name of the module being imported. If the module to be imported is contained in a package, then the parent package’s <a class="reference internal" href="../reference/import#path__" title="__path__"><code>__path__</code></a> attribute is passed in as a second argument. The method returns a <a class="reference internal" href="../glossary#term-module-spec"><span class="xref std std-term">module spec</span></a>, or <code>None</code> if the module cannot be found.</p> <div class="admonition seealso"> <p class="admonition-title">See also</p> <dl class="simple"> <dt> +<code></code> <a class="reference internal" href="importlib#importlib.abc.MetaPathFinder" title="importlib.abc.MetaPathFinder"><code>importlib.abc.MetaPathFinder</code></a> +</dt> +<dd> +<p>The abstract base class defining the interface of finder objects on <a class="reference internal" href="#sys.meta_path" title="sys.meta_path"><code>meta_path</code></a>.</p> </dd> <dt> +<code></code> <a class="reference internal" href="importlib#importlib.machinery.ModuleSpec" title="importlib.machinery.ModuleSpec"><code>importlib.machinery.ModuleSpec</code></a> +</dt> +<dd> +<p>The concrete class which <a class="reference internal" href="importlib#importlib.abc.MetaPathFinder.find_spec" title="importlib.abc.MetaPathFinder.find_spec"><code>find_spec()</code></a> should return instances of.</p> </dd> </dl> </div> <div class="versionchanged"> <p><span class="versionmodified changed">Changed in version 3.4: </span><a class="reference internal" href="../glossary#term-module-spec"><span class="xref std std-term">Module specs</span></a> were introduced in Python 3.4, by <span class="target" id="index-20"></span><a class="pep reference external" href="https://peps.python.org/pep-0451/"><strong>PEP 451</strong></a>. Earlier versions of Python looked for a method called <code>find_module()</code>. This is still called as a fallback if a <a class="reference internal" href="#sys.meta_path" title="sys.meta_path"><code>meta_path</code></a> entry doesn’t have a <a class="reference internal" href="importlib#importlib.abc.MetaPathFinder.find_spec" title="importlib.abc.MetaPathFinder.find_spec"><code>find_spec()</code></a> method.</p> </div> </dd> +</dl> <dl class="py data"> <dt class="sig sig-object py" id="sys.modules"> +<code>sys.modules</code> </dt> <dd> +<p>This is a dictionary that maps module names to modules which have already been loaded. This can be manipulated to force reloading of modules and other tricks. However, replacing the dictionary will not necessarily work as expected and deleting essential items from the dictionary may cause Python to fail. If you want to iterate over this global dictionary always use <code>sys.modules.copy()</code> or <code>tuple(sys.modules)</code> to avoid exceptions as its size may change during iteration as a side effect of code or activity in other threads.</p> </dd> +</dl> <dl class="py data"> <dt class="sig sig-object py" id="sys.orig_argv"> +<code>sys.orig_argv</code> </dt> <dd> +<p>The list of the original command line arguments passed to the Python executable.</p> <p>See also <a class="reference internal" href="#sys.argv" title="sys.argv"><code>sys.argv</code></a>.</p> <div class="versionadded"> <p><span class="versionmodified added">New in version 3.10.</span></p> </div> </dd> +</dl> <dl class="py data"> <dt class="sig sig-object py" id="sys.path"> +<code>sys.path</code> </dt> <dd> +<p id="index-21">A list of strings that specifies the search path for modules. Initialized from the environment variable <span class="target" id="index-22"></span><a class="reference internal" href="../using/cmdline#envvar-PYTHONPATH"><code>PYTHONPATH</code></a>, plus an installation-dependent default.</p> <p>By default, as initialized upon program startup, a potentially unsafe path is prepended to <a class="reference internal" href="#sys.path" title="sys.path"><code>sys.path</code></a> (<em>before</em> the entries inserted as a result of <span class="target" id="index-23"></span><a class="reference internal" href="../using/cmdline#envvar-PYTHONPATH"><code>PYTHONPATH</code></a>):</p> <ul class="simple"> <li> +<code>python -m module</code> command line: prepend the current working directory.</li> <li> +<code>python script.py</code> command line: prepend the script’s directory. If it’s a symbolic link, resolve symbolic links.</li> <li> +<code>python -c code</code> and <code>python</code> (REPL) command lines: prepend an empty string, which means the current working directory.</li> </ul> <p>To not prepend this potentially unsafe path, use the <a class="reference internal" href="../using/cmdline#cmdoption-P"><code>-P</code></a> command line option or the <span class="target" id="index-24"></span><a class="reference internal" href="../using/cmdline#envvar-PYTHONSAFEPATH"><code>PYTHONSAFEPATH</code></a> environment variable.</p> <p>A program is free to modify this list for its own purposes. Only strings should be added to <a class="reference internal" href="#sys.path" title="sys.path"><code>sys.path</code></a>; all other data types are ignored during import.</p> <div class="admonition seealso"> <p class="admonition-title">See also</p> <ul class="simple"> <li>Module <a class="reference internal" href="site#module-site" title="site: Module responsible for site-specific configuration."><code>site</code></a> This describes how to use .pth files to extend <a class="reference internal" href="#sys.path" title="sys.path"><code>sys.path</code></a>.</li> </ul> </div> </dd> +</dl> <dl class="py data"> <dt class="sig sig-object py" id="sys.path_hooks"> +<code>sys.path_hooks</code> </dt> <dd> +<p>A list of callables that take a path argument to try to create a <a class="reference internal" href="../glossary#term-finder"><span class="xref std std-term">finder</span></a> for the path. If a finder can be created, it is to be returned by the callable, else raise <a class="reference internal" href="exceptions#ImportError" title="ImportError"><code>ImportError</code></a>.</p> <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> </dd> +</dl> <dl class="py data"> <dt class="sig sig-object py" id="sys.path_importer_cache"> +<code>sys.path_importer_cache</code> </dt> <dd> +<p>A dictionary acting as a cache for <a class="reference internal" href="../glossary#term-finder"><span class="xref std std-term">finder</span></a> objects. The keys are paths that have been passed to <a class="reference internal" href="#sys.path_hooks" title="sys.path_hooks"><code>sys.path_hooks</code></a> and the values are the finders that are found. If a path is a valid file system path but no finder is found on <a class="reference internal" href="#sys.path_hooks" title="sys.path_hooks"><code>sys.path_hooks</code></a> then <code>None</code> is stored.</p> <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> </dd> +</dl> <dl class="py data"> <dt class="sig sig-object py" id="sys.platform"> +<code>sys.platform</code> </dt> <dd> +<p>This string contains a platform identifier that can be used to append platform-specific components to <a class="reference internal" href="#sys.path" title="sys.path"><code>sys.path</code></a>, for instance.</p> <p>For Unix systems, except on Linux and AIX, this is the lowercased OS name as returned by <code>uname -s</code> with the first part of the version as returned by <code>uname -r</code> appended, e.g. <code>'sunos5'</code> or <code>'freebsd8'</code>, <em>at the time when Python was built</em>. Unless you want to test for a specific system version, it is therefore recommended to use the following idiom:</p> <pre data-language="python">if sys.platform.startswith('freebsd'): + # FreeBSD-specific code here... +elif sys.platform.startswith('linux'): + # Linux-specific code here... +elif sys.platform.startswith('aix'): + # AIX-specific code here... +</pre> <p>For other systems, the values are:</p> <table class="docutils align-default"> <thead> <tr> +<th class="head"><p>System</p></th> <th class="head"><p><code>platform</code> value</p></th> </tr> </thead> <tr> +<td><p>AIX</p></td> <td><p><code>'aix'</code></p></td> </tr> <tr> +<td><p>Emscripten</p></td> <td><p><code>'emscripten'</code></p></td> </tr> <tr> +<td><p>Linux</p></td> <td><p><code>'linux'</code></p></td> </tr> <tr> +<td><p>WASI</p></td> <td><p><code>'wasi'</code></p></td> </tr> <tr> +<td><p>Windows</p></td> <td><p><code>'win32'</code></p></td> </tr> <tr> +<td><p>Windows/Cygwin</p></td> <td><p><code>'cygwin'</code></p></td> </tr> <tr> +<td><p>macOS</p></td> <td><p><code>'darwin'</code></p></td> </tr> </table> <div class="versionchanged"> <p><span class="versionmodified changed">Changed in version 3.3: </span>On Linux, <a class="reference internal" href="#sys.platform" title="sys.platform"><code>sys.platform</code></a> doesn’t contain the major version anymore. It is always <code>'linux'</code>, instead of <code>'linux2'</code> or <code>'linux3'</code>. Since older Python versions include the version number, it is recommended to always use the <code>startswith</code> idiom presented above.</p> </div> <div class="versionchanged"> <p><span class="versionmodified changed">Changed in version 3.8: </span>On AIX, <a class="reference internal" href="#sys.platform" title="sys.platform"><code>sys.platform</code></a> doesn’t contain the major version anymore. It is always <code>'aix'</code>, instead of <code>'aix5'</code> or <code>'aix7'</code>. Since older Python versions include the version number, it is recommended to always use the <code>startswith</code> idiom presented above.</p> </div> <div class="admonition seealso"> <p class="admonition-title">See also</p> <p><a class="reference internal" href="os#os.name" title="os.name"><code>os.name</code></a> has a coarser granularity. <a class="reference internal" href="os#os.uname" title="os.uname"><code>os.uname()</code></a> gives system-dependent version information.</p> <p>The <a class="reference internal" href="platform#module-platform" title="platform: Retrieves as much platform identifying data as possible."><code>platform</code></a> module provides detailed checks for the system’s identity.</p> </div> </dd> +</dl> <dl class="py data"> <dt class="sig sig-object py" id="sys.platlibdir"> +<code>sys.platlibdir</code> </dt> <dd> +<p>Name of the platform-specific library directory. It is used to build the path of standard library and the paths of installed extension modules.</p> <p>It is equal to <code>"lib"</code> on most platforms. On Fedora and SuSE, it is equal to <code>"lib64"</code> on 64-bit platforms which gives the following <code>sys.path</code> paths (where <code>X.Y</code> is the Python <code>major.minor</code> version):</p> <ul class="simple"> <li> +<code>/usr/lib64/pythonX.Y/</code>: Standard library (like <code>os.py</code> of the <a class="reference internal" href="os#module-os" title="os: Miscellaneous operating system interfaces."><code>os</code></a> module)</li> <li> +<code>/usr/lib64/pythonX.Y/lib-dynload/</code>: C extension modules of the standard library (like the <a class="reference internal" href="errno#module-errno" title="errno: Standard errno system symbols."><code>errno</code></a> module, the exact filename is platform specific)</li> <li> +<code>/usr/lib/pythonX.Y/site-packages/</code> (always use <code>lib</code>, not <a class="reference internal" href="#sys.platlibdir" title="sys.platlibdir"><code>sys.platlibdir</code></a>): Third-party modules</li> <li> +<code>/usr/lib64/pythonX.Y/site-packages/</code>: C extension modules of third-party packages</li> </ul> <div class="versionadded"> <p><span class="versionmodified added">New in version 3.9.</span></p> </div> </dd> +</dl> <dl class="py data"> <dt class="sig sig-object py" id="sys.prefix"> +<code>sys.prefix</code> </dt> <dd> +<p>A string giving the site-specific directory prefix where the platform independent Python files are installed; on Unix, the default is <code>/usr/local</code>. This can be set at build time with the <a class="reference internal" href="../using/configure#cmdoption-prefix"><code>--prefix</code></a> argument to the <strong class="program">configure</strong> script. See <a class="reference internal" href="sysconfig#installation-paths"><span class="std std-ref">Installation paths</span></a> for derived paths.</p> <div class="admonition note"> <p class="admonition-title">Note</p> <p>If a <a class="reference internal" href="venv#venv-def"><span class="std std-ref">virtual environment</span></a> is in effect, this value will be changed in <code>site.py</code> to point to the virtual environment. The value for the Python installation will still be available, via <a class="reference internal" href="#sys.base_prefix" title="sys.base_prefix"><code>base_prefix</code></a>.</p> </div> </dd> +</dl> <dl class="py data"> <dt class="sig sig-object py" id="sys.ps1"> +<code>sys.ps1</code> </dt> <dt class="sig sig-object py" id="sys.ps2"> +<code>sys.ps2</code> </dt> <dd> +<p id="index-27">Strings specifying the primary and secondary prompt of the interpreter. These are only defined if the interpreter is in interactive mode. Their initial values in this case are <code>'>>> '</code> and <code>'... '</code>. If a non-string object is assigned to either variable, its <a class="reference internal" href="stdtypes#str" title="str"><code>str()</code></a> is re-evaluated each time the interpreter prepares to read a new interactive command; this can be used to implement a dynamic prompt.</p> </dd> +</dl> <dl class="py function"> <dt class="sig sig-object py" id="sys.setdlopenflags"> +<code>sys.setdlopenflags(n)</code> </dt> <dd> +<p>Set the flags used by the interpreter for <code>dlopen()</code> calls, such as when the interpreter loads extension modules. Among other things, this will enable a lazy resolving of symbols when importing a module, if called as <code>sys.setdlopenflags(0)</code>. To share symbols across extension modules, call as <code>sys.setdlopenflags(os.RTLD_GLOBAL)</code>. Symbolic names for the flag values can be found in the <a class="reference internal" href="os#module-os" title="os: Miscellaneous operating system interfaces."><code>os</code></a> module (<code>RTLD_<em>xxx</em></code> constants, e.g. <a class="reference internal" href="os#os.RTLD_LAZY" title="os.RTLD_LAZY"><code>os.RTLD_LAZY</code></a>).</p> <div class="availability docutils container"> <p><a class="reference internal" href="https://docs.python.org/3.12/library/intro.html#availability"><span class="std std-ref">Availability</span></a>: Unix.</p> </div> </dd> +</dl> <dl class="py function"> <dt class="sig sig-object py" id="sys.set_int_max_str_digits"> +<code>sys.set_int_max_str_digits(maxdigits)</code> </dt> <dd> +<p>Set the <a class="reference internal" href="stdtypes#int-max-str-digits"><span class="std std-ref">integer string conversion length limitation</span></a> used by this interpreter. See also <a class="reference internal" href="#sys.get_int_max_str_digits" title="sys.get_int_max_str_digits"><code>get_int_max_str_digits()</code></a>.</p> <div class="versionadded"> <p><span class="versionmodified added">New in version 3.11.</span></p> </div> </dd> +</dl> <dl class="py function"> <dt class="sig sig-object py" id="sys.setprofile"> +<code>sys.setprofile(profilefunc)</code> </dt> <dd> +<p id="index-28">Set the system’s profile function, which allows you to implement a Python source code profiler in Python. See chapter <a class="reference internal" href="profile#profile"><span class="std std-ref">The Python Profilers</span></a> for more information on the Python profiler. The system’s profile function is called similarly to the system’s trace function (see <a class="reference internal" href="#sys.settrace" title="sys.settrace"><code>settrace()</code></a>), but it is called with different events, for example it isn’t called for each executed line of code (only on call and return, but the return event is reported even when an exception has been set). The function is thread-specific, but there is no way for the profiler to know about context switches between threads, so it does not make sense to use this in the presence of multiple threads. Also, its return value is not used, so it can simply return <code>None</code>. Error in the profile function will cause itself unset.</p> <div class="admonition note"> <p class="admonition-title">Note</p> <p>The same tracing mechanism is used for <code>setprofile()</code> as <a class="reference internal" href="#sys.settrace" title="sys.settrace"><code>settrace()</code></a>. To trace calls with <code>setprofile()</code> inside a tracing function (e.g. in a debugger breakpoint), see <a class="reference internal" href="#sys.call_tracing" title="sys.call_tracing"><code>call_tracing()</code></a>.</p> </div> <p>Profile functions should have three arguments: <em>frame</em>, <em>event</em>, and <em>arg</em>. <em>frame</em> is the current stack frame. <em>event</em> is a string: <code>'call'</code>, <code>'return'</code>, <code>'c_call'</code>, <code>'c_return'</code>, or <code>'c_exception'</code>. <em>arg</em> depends on the event type.</p> <p>The events have the following meaning:</p> <dl class="simple"> <dt> +<code>'call'</code> </dt> +<dd> +<p>A function is called (or some other code block entered). The profile function is called; <em>arg</em> is <code>None</code>.</p> </dd> <dt> +<code>'return'</code> </dt> +<dd> +<p>A function (or other code block) is about to return. The profile function is called; <em>arg</em> is the value that will be returned, or <code>None</code> if the event is caused by an exception being raised.</p> </dd> <dt> +<code>'c_call'</code> </dt> +<dd> +<p>A C function is about to be called. This may be an extension function or a built-in. <em>arg</em> is the C function object.</p> </dd> <dt> +<code>'c_return'</code> </dt> +<dd> +<p>A C function has returned. <em>arg</em> is the C function object.</p> </dd> <dt> +<code>'c_exception'</code> </dt> +<dd> +<p>A C function has raised an exception. <em>arg</em> is the C function object.</p> </dd> </dl> <p class="audit-hook">Raises an <a class="reference internal" href="#auditing"><span class="std std-ref">auditing event</span></a> <code>sys.setprofile</code> with no arguments.</p> </dd> +</dl> <dl class="py function"> <dt class="sig sig-object py" id="sys.setrecursionlimit"> +<code>sys.setrecursionlimit(limit)</code> </dt> <dd> +<p>Set the maximum depth of the Python interpreter stack to <em>limit</em>. This limit prevents infinite recursion from causing an overflow of the C stack and crashing Python.</p> <p>The highest possible limit is platform-dependent. A user may need to set the limit higher when they have a program that requires deep recursion and a platform that supports a higher limit. This should be done with care, because a too-high limit can lead to a crash.</p> <p>If the new limit is too low at the current recursion depth, a <a class="reference internal" href="exceptions#RecursionError" title="RecursionError"><code>RecursionError</code></a> exception is raised.</p> <div class="versionchanged"> <p><span class="versionmodified changed">Changed in version 3.5.1: </span>A <a class="reference internal" href="exceptions#RecursionError" title="RecursionError"><code>RecursionError</code></a> exception is now raised if the new limit is too low at the current recursion depth.</p> </div> </dd> +</dl> <dl class="py function"> <dt class="sig sig-object py" id="sys.setswitchinterval"> +<code>sys.setswitchinterval(interval)</code> </dt> <dd> +<p>Set the interpreter’s thread switch interval (in seconds). This floating-point value determines the ideal duration of the “timeslices” allocated to concurrently running Python threads. Please note that the actual value can be higher, especially if long-running internal functions or methods are used. Also, which thread becomes scheduled at the end of the interval is the operating system’s decision. The interpreter doesn’t have its own scheduler.</p> <div class="versionadded"> <p><span class="versionmodified added">New in version 3.2.</span></p> </div> </dd> +</dl> <dl class="py function"> <dt class="sig sig-object py" id="sys.settrace"> +<code>sys.settrace(tracefunc)</code> </dt> <dd> +<p id="index-29">Set the system’s trace function, which allows you to implement a Python source code debugger in Python. The function is thread-specific; for a debugger to support multiple threads, it must register a trace function using <a class="reference internal" href="#sys.settrace" title="sys.settrace"><code>settrace()</code></a> for each thread being debugged or use <a class="reference internal" href="threading#threading.settrace" title="threading.settrace"><code>threading.settrace()</code></a>.</p> <p>Trace functions should have three arguments: <em>frame</em>, <em>event</em>, and <em>arg</em>. <em>frame</em> is the current stack frame. <em>event</em> is a string: <code>'call'</code>, <code>'line'</code>, <code>'return'</code>, <code>'exception'</code> or <code>'opcode'</code>. <em>arg</em> depends on the event type.</p> <p>The trace function is invoked (with <em>event</em> set to <code>'call'</code>) whenever a new local scope is entered; it should return a reference to a local trace function to be used for the new scope, or <code>None</code> if the scope shouldn’t be traced.</p> <p>The local trace function should return a reference to itself, or to another function which would then be used as the local trace function for the scope.</p> <p>If there is any error occurred in the trace function, it will be unset, just like <code>settrace(None)</code> is called.</p> <div class="admonition note"> <p class="admonition-title">Note</p> <p>Tracing is disabled while calling the trace function (e.g. a function set by <code>settrace()</code>). For recursive tracing see <a class="reference internal" href="#sys.call_tracing" title="sys.call_tracing"><code>call_tracing()</code></a>.</p> </div> <p>The events have the following meaning:</p> <dl class="simple"> <dt> +<code>'call'</code> </dt> +<dd> +<p>A function is called (or some other code block entered). The global trace function is called; <em>arg</em> is <code>None</code>; the return value specifies the local trace function.</p> </dd> <dt> +<code>'line'</code> </dt> +<dd> +<p>The interpreter is about to execute a new line of code or re-execute the condition of a loop. The local trace function is called; <em>arg</em> is <code>None</code>; the return value specifies the new local trace function. See <code>Objects/lnotab_notes.txt</code> for a detailed explanation of how this works. Per-line events may be disabled for a frame by setting <a class="reference internal" href="../reference/datamodel#frame.f_trace_lines" title="frame.f_trace_lines"><code>f_trace_lines</code></a> to <a class="reference internal" href="constants#False" title="False"><code>False</code></a> on that <a class="reference internal" href="../reference/datamodel#frame-objects"><span class="std std-ref">frame</span></a>.</p> </dd> <dt> +<code>'return'</code> </dt> +<dd> +<p>A function (or other code block) is about to return. The local trace function is called; <em>arg</em> is the value that will be returned, or <code>None</code> if the event is caused by an exception being raised. The trace function’s return value is ignored.</p> </dd> <dt> +<code>'exception'</code> </dt> +<dd> +<p>An exception has occurred. The local trace function is called; <em>arg</em> is a tuple <code>(exception, value, traceback)</code>; the return value specifies the new local trace function.</p> </dd> <dt> +<code>'opcode'</code> </dt> +<dd> +<p>The interpreter is about to execute a new opcode (see <a class="reference internal" href="dis#module-dis" title="dis: Disassembler for Python bytecode."><code>dis</code></a> for opcode details). The local trace function is called; <em>arg</em> is <code>None</code>; the return value specifies the new local trace function. Per-opcode events are not emitted by default: they must be explicitly requested by setting <a class="reference internal" href="../reference/datamodel#frame.f_trace_opcodes" title="frame.f_trace_opcodes"><code>f_trace_opcodes</code></a> to <a class="reference internal" href="constants#True" title="True"><code>True</code></a> on the <a class="reference internal" href="../reference/datamodel#frame-objects"><span class="std std-ref">frame</span></a>.</p> </dd> </dl> <p>Note that as an exception is propagated down the chain of callers, an <code>'exception'</code> event is generated at each level.</p> <p>For more fine-grained usage, it’s possible to set a trace function by assigning <code>frame.f_trace = tracefunc</code> explicitly, rather than relying on it being set indirectly via the return value from an already installed trace function. This is also required for activating the trace function on the current frame, which <a class="reference internal" href="#sys.settrace" title="sys.settrace"><code>settrace()</code></a> doesn’t do. Note that in order for this to work, a global tracing function must have been installed with <a class="reference internal" href="#sys.settrace" title="sys.settrace"><code>settrace()</code></a> in order to enable the runtime tracing machinery, but it doesn’t need to be the same tracing function (e.g. it could be a low overhead tracing function that simply returns <code>None</code> to disable itself immediately on each frame).</p> <p>For more information on code and frame objects, refer to <a class="reference internal" href="../reference/datamodel#types"><span class="std std-ref">The standard type hierarchy</span></a>.</p> <p class="audit-hook">Raises an <a class="reference internal" href="#auditing"><span class="std std-ref">auditing event</span></a> <code>sys.settrace</code> with no arguments.</p> <div class="impl-detail compound"> <p><strong>CPython implementation detail:</strong> The <a class="reference internal" href="#sys.settrace" title="sys.settrace"><code>settrace()</code></a> function is intended only for implementing debuggers, profilers, coverage tools and the like. Its behavior is part of the implementation platform, rather than part of the language definition, and thus may not be available in all Python implementations.</p> </div> <div class="versionchanged"> <p><span class="versionmodified changed">Changed in version 3.7: </span><code>'opcode'</code> event type added; <a class="reference internal" href="../reference/datamodel#frame.f_trace_lines" title="frame.f_trace_lines"><code>f_trace_lines</code></a> and <a class="reference internal" href="../reference/datamodel#frame.f_trace_opcodes" title="frame.f_trace_opcodes"><code>f_trace_opcodes</code></a> attributes added to frames</p> </div> </dd> +</dl> <dl class="py function"> <dt class="sig sig-object py" id="sys.set_asyncgen_hooks"> +<code>sys.set_asyncgen_hooks(firstiter, finalizer)</code> </dt> <dd> +<p>Accepts two optional keyword arguments which are callables that accept an <a class="reference internal" href="../glossary#term-asynchronous-generator-iterator"><span class="xref std std-term">asynchronous generator iterator</span></a> as an argument. The <em>firstiter</em> callable will be called when an asynchronous generator is iterated for the first time. The <em>finalizer</em> will be called when an asynchronous generator is about to be garbage collected.</p> <p class="audit-hook">Raises an <a class="reference internal" href="#auditing"><span class="std std-ref">auditing event</span></a> <code>sys.set_asyncgen_hooks_firstiter</code> with no arguments.</p> <p class="audit-hook">Raises an <a class="reference internal" href="#auditing"><span class="std std-ref">auditing event</span></a> <code>sys.set_asyncgen_hooks_finalizer</code> with no arguments.</p> <p>Two auditing events are raised because the underlying API consists of two calls, each of which must raise its own event.</p> <div class="versionadded"> <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 <em>finalizer</em> method see the implementation of <code>asyncio.Loop.shutdown_asyncgens</code> in <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> </div> <div class="admonition note"> <p class="admonition-title">Note</p> <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> for details.)</p> </div> </dd> +</dl> <dl class="py function"> <dt class="sig sig-object py" id="sys.set_coroutine_origin_tracking_depth"> +<code>sys.set_coroutine_origin_tracking_depth(depth)</code> </dt> <dd> +<p>Allows enabling or disabling coroutine origin tracking. When enabled, the <code>cr_origin</code> attribute on coroutine objects will contain a tuple of (filename, line number, function name) tuples describing the traceback where the coroutine object was created, with the most recent call first. When disabled, <code>cr_origin</code> will be None.</p> <p>To enable, pass a <em>depth</em> value greater than zero; this sets the number of frames whose information will be captured. To disable, pass set <em>depth</em> to zero.</p> <p>This setting is thread-specific.</p> <div class="versionadded"> <p><span class="versionmodified added">New in version 3.7.</span></p> </div> <div class="admonition note"> <p class="admonition-title">Note</p> <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> for details.) Use it only for debugging purposes.</p> </div> </dd> +</dl> <dl class="py function"> <dt class="sig sig-object py" id="sys.activate_stack_trampoline"> +<code>sys.activate_stack_trampoline(backend, /)</code> </dt> <dd> +<p>Activate the stack profiler trampoline <em>backend</em>. The only supported backend is <code>"perf"</code>.</p> <div class="availability docutils container"> <p><a class="reference internal" href="https://docs.python.org/3.12/library/intro.html#availability"><span class="std std-ref">Availability</span></a>: Linux.</p> </div> <div class="versionadded"> <p><span class="versionmodified added">New in version 3.12.</span></p> </div> <div class="admonition seealso"> <p class="admonition-title">See also</p> <ul class="simple"> <li><a class="reference internal" href="../howto/perf_profiling#perf-profiling"><span class="std std-ref">Python support for the Linux perf profiler</span></a></li> <li><a class="reference external" href="https://perf.wiki.kernel.org">https://perf.wiki.kernel.org</a></li> </ul> </div> </dd> +</dl> <dl class="py function"> <dt class="sig sig-object py" id="sys.deactivate_stack_trampoline"> +<code>sys.deactivate_stack_trampoline()</code> </dt> <dd> +<p>Deactivate the current stack profiler trampoline backend.</p> <p>If no stack profiler is activated, this function has no effect.</p> <div class="availability docutils container"> <p><a class="reference internal" href="https://docs.python.org/3.12/library/intro.html#availability"><span class="std std-ref">Availability</span></a>: Linux.</p> </div> <div class="versionadded"> <p><span class="versionmodified added">New in version 3.12.</span></p> </div> </dd> +</dl> <dl class="py function"> <dt class="sig sig-object py" id="sys.is_stack_trampoline_active"> +<code>sys.is_stack_trampoline_active()</code> </dt> <dd> +<p>Return <code>True</code> if a stack profiler trampoline is active.</p> <div class="availability docutils container"> <p><a class="reference internal" href="https://docs.python.org/3.12/library/intro.html#availability"><span class="std std-ref">Availability</span></a>: Linux.</p> </div> <div class="versionadded"> <p><span class="versionmodified added">New in version 3.12.</span></p> </div> </dd> +</dl> <dl class="py function"> <dt class="sig sig-object py" id="sys._enablelegacywindowsfsencoding"> +<code>sys._enablelegacywindowsfsencoding()</code> </dt> <dd> +<p>Changes the <a class="reference internal" href="../glossary#term-filesystem-encoding-and-error-handler"><span class="xref std std-term">filesystem encoding and error handler</span></a> to ‘mbcs’ and ‘replace’ respectively, for consistency with versions of Python prior to 3.6.</p> <p>This is equivalent to defining the <span class="target" id="index-33"></span><a class="reference internal" href="../using/cmdline#envvar-PYTHONLEGACYWINDOWSFSENCODING"><code>PYTHONLEGACYWINDOWSFSENCODING</code></a> environment variable before launching Python.</p> <p>See also <a class="reference internal" href="#sys.getfilesystemencoding" title="sys.getfilesystemencoding"><code>sys.getfilesystemencoding()</code></a> and <a class="reference internal" href="#sys.getfilesystemencodeerrors" title="sys.getfilesystemencodeerrors"><code>sys.getfilesystemencodeerrors()</code></a>.</p> <div class="availability docutils container"> <p><a class="reference internal" href="https://docs.python.org/3.12/library/intro.html#availability"><span class="std std-ref">Availability</span></a>: Windows.</p> </div> <div class="versionadded"> <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> </div> </dd> +</dl> <dl class="py data"> <dt class="sig sig-object py" id="sys.stdin"> +<code>sys.stdin</code> </dt> <dt class="sig sig-object py" id="sys.stdout"> +<code>sys.stdout</code> </dt> <dt class="sig sig-object py" id="sys.stderr"> +<code>sys.stderr</code> </dt> <dd> +<p><a class="reference internal" href="../glossary#term-file-object"><span class="xref std std-term">File objects</span></a> used by the interpreter for standard input, output and errors:</p> <ul class="simple"> <li> +<code>stdin</code> is used for all interactive input (including calls to <a class="reference internal" href="functions#input" title="input"><code>input()</code></a>);</li> <li> +<code>stdout</code> is used for the output of <a class="reference internal" href="functions#print" title="print"><code>print()</code></a> and <a class="reference internal" href="../glossary#term-expression"><span class="xref std std-term">expression</span></a> statements and for the prompts of <a class="reference internal" href="functions#input" title="input"><code>input()</code></a>;</li> <li>The interpreter’s own prompts and its error messages go to <code>stderr</code>.</li> </ul> <p>These streams are regular <a class="reference internal" href="../glossary#term-text-file"><span class="xref std std-term">text files</span></a> like those returned by the <a class="reference internal" href="functions#open" title="open"><code>open()</code></a> function. Their parameters are chosen as follows:</p> <ul> <li> +<p>The encoding and error handling are is initialized from <a class="reference internal" href="../c-api/init_config#c.PyConfig.stdio_encoding" title="PyConfig.stdio_encoding"><code>PyConfig.stdio_encoding</code></a> and <a class="reference internal" href="../c-api/init_config#c.PyConfig.stdio_errors" title="PyConfig.stdio_errors"><code>PyConfig.stdio_errors</code></a>.</p> <p>On Windows, UTF-8 is used for the console device. Non-character devices such as disk files and pipes use the system locale encoding (i.e. the ANSI codepage). Non-console character devices such as NUL (i.e. where <code>isatty()</code> returns <code>True</code>) use the value of the console input and output codepages at startup, respectively for stdin and stdout/stderr. This defaults to the system <a class="reference internal" href="../glossary#term-locale-encoding"><span class="xref std std-term">locale encoding</span></a> if the process is not initially attached to a console.</p> <p>The special behaviour of the console can be overridden by setting the environment variable PYTHONLEGACYWINDOWSSTDIO before starting Python. In that case, the console codepages are used as for any other character device.</p> <p>Under all platforms, you can override the character encoding by setting the <span class="target" id="index-35"></span><a class="reference internal" href="../using/cmdline#envvar-PYTHONIOENCODING"><code>PYTHONIOENCODING</code></a> environment variable before starting Python or by using the new <a class="reference internal" href="../using/cmdline#cmdoption-X"><code>-X</code></a> <code>utf8</code> command line option and <span class="target" id="index-36"></span><a class="reference internal" href="../using/cmdline#envvar-PYTHONUTF8"><code>PYTHONUTF8</code></a> environment variable. However, for the Windows console, this only applies when <span class="target" id="index-37"></span><a class="reference internal" href="../using/cmdline#envvar-PYTHONLEGACYWINDOWSSTDIO"><code>PYTHONLEGACYWINDOWSSTDIO</code></a> is also set.</p> </li> <li>When interactive, the <code>stdout</code> stream is line-buffered. Otherwise, it is block-buffered like regular text files. The <code>stderr</code> stream is line-buffered in both cases. You can make both streams unbuffered by passing the <a class="reference internal" href="../using/cmdline#cmdoption-u"><code>-u</code></a> command-line option or setting the <span class="target" id="index-38"></span><a class="reference internal" href="../using/cmdline#envvar-PYTHONUNBUFFERED"><code>PYTHONUNBUFFERED</code></a> environment variable.</li> </ul> <div class="versionchanged"> <p><span class="versionmodified changed">Changed in version 3.9: </span>Non-interactive <code>stderr</code> is now line-buffered instead of fully buffered.</p> </div> <div class="admonition note"> <p class="admonition-title">Note</p> <p>To write or read binary data from/to the standard streams, use the underlying binary <a class="reference internal" href="io#io.TextIOBase.buffer" title="io.TextIOBase.buffer"><code>buffer</code></a> object. For example, to write bytes to <a class="reference internal" href="#sys.stdout" title="sys.stdout"><code>stdout</code></a>, use <code>sys.stdout.buffer.write(b'abc')</code>.</p> <p>However, if you are writing a library (and do not control in which context its code will be executed), be aware that the standard streams may be replaced with file-like objects like <a class="reference internal" href="io#io.StringIO" title="io.StringIO"><code>io.StringIO</code></a> which do not support the <code>buffer</code> attribute.</p> </div> </dd> +</dl> <dl class="py data"> <dt class="sig sig-object py" id="sys.__stdin__"> +<code>sys.__stdin__</code> </dt> <dt class="sig sig-object py" id="sys.__stdout__"> +<code>sys.__stdout__</code> </dt> <dt class="sig sig-object py" id="sys.__stderr__"> +<code>sys.__stderr__</code> </dt> <dd> +<p>These objects contain the original values of <code>stdin</code>, <code>stderr</code> and <code>stdout</code> at the start of the program. They are used during finalization, and could be useful to print to the actual standard stream no matter if the <code>sys.std*</code> object has been redirected.</p> <p>It can also be used to restore the actual files to known working file objects in case they have been overwritten with a broken object. However, the preferred way to do this is to explicitly save the previous stream before replacing it, and restore the saved object.</p> <div class="admonition note"> <p class="admonition-title">Note</p> <p>Under some conditions <code>stdin</code>, <code>stdout</code> and <code>stderr</code> as well as the original values <code>__stdin__</code>, <code>__stdout__</code> and <code>__stderr__</code> can be <code>None</code>. It is usually the case for Windows GUI apps that aren’t connected to a console and Python apps started with <strong class="program">pythonw</strong>.</p> </div> </dd> +</dl> <dl class="py data"> <dt class="sig sig-object py" id="sys.stdlib_module_names"> +<code>sys.stdlib_module_names</code> </dt> <dd> +<p>A frozenset of strings containing the names of standard library modules.</p> <p>It is the same on all platforms. Modules which are not available on some platforms and modules disabled at Python build are also listed. All module kinds are listed: pure Python, built-in, frozen and extension modules. Test modules are excluded.</p> <p>For packages, only the main package is listed: sub-packages and sub-modules are not listed. For example, the <code>email</code> package is listed, but the <code>email.mime</code> sub-package and the <code>email.message</code> sub-module are not listed.</p> <p>See also the <a class="reference internal" href="#sys.builtin_module_names" title="sys.builtin_module_names"><code>sys.builtin_module_names</code></a> list.</p> <div class="versionadded"> <p><span class="versionmodified added">New in version 3.10.</span></p> </div> </dd> +</dl> <dl class="py data"> <dt class="sig sig-object py" id="sys.thread_info"> +<code>sys.thread_info</code> </dt> <dd> +<p>A <a class="reference internal" href="../glossary#term-named-tuple"><span class="xref std std-term">named tuple</span></a> holding information about the thread implementation.</p> <dl class="py attribute"> <dt class="sig sig-object py" id="sys.thread_info.name"> +<code>thread_info.name</code> </dt> <dd> +<p>The name of the thread implementation:</p> <ul class="simple"> <li> +<code>"nt"</code>: Windows threads</li> <li> +<code>"pthread"</code>: POSIX threads</li> <li> +<code>"pthread-stubs"</code>: stub POSIX threads (on WebAssembly platforms without threading support)</li> <li> +<code>"solaris"</code>: Solaris threads</li> </ul> </dd> +</dl> <dl class="py attribute"> <dt class="sig sig-object py" id="sys.thread_info.lock"> +<code>thread_info.lock</code> </dt> <dd> +<p>The name of the lock implementation:</p> <ul class="simple"> <li> +<code>"semaphore"</code>: a lock uses a semaphore</li> <li> +<code>"mutex+cond"</code>: a lock uses a mutex and a condition variable</li> <li> +<code>None</code> if this information is unknown</li> </ul> </dd> +</dl> <dl class="py attribute"> <dt class="sig sig-object py" id="sys.thread_info.version"> +<code>thread_info.version</code> </dt> <dd> +<p>The name and version of the thread library. It is a string, or <code>None</code> if this information is unknown.</p> </dd> +</dl> <div class="versionadded"> <p><span class="versionmodified added">New in version 3.3.</span></p> </div> </dd> +</dl> <dl class="py data"> <dt class="sig sig-object py" id="sys.tracebacklimit"> +<code>sys.tracebacklimit</code> </dt> <dd> +<p>When this variable is set to an integer value, it determines the maximum number of levels of traceback information printed when an unhandled exception occurs. The default is <code>1000</code>. When set to <code>0</code> or less, all traceback information is suppressed and only the exception type and value are printed.</p> </dd> +</dl> <dl class="py function"> <dt class="sig sig-object py" id="sys.unraisablehook"> +<code>sys.unraisablehook(unraisable, /)</code> </dt> <dd> +<p>Handle an unraisable exception.</p> <p>Called when an exception has occurred but there is no way for Python to handle it. For example, when a destructor raises an exception or during garbage collection (<a class="reference internal" href="gc#gc.collect" title="gc.collect"><code>gc.collect()</code></a>).</p> <p>The <em>unraisable</em> argument has the following attributes:</p> <ul class="simple"> <li> +<code>exc_type</code>: Exception type.</li> <li> +<code>exc_value</code>: Exception value, can be <code>None</code>.</li> <li> +<code>exc_traceback</code>: Exception traceback, can be <code>None</code>.</li> <li> +<code>err_msg</code>: Error message, can be <code>None</code>.</li> <li> +<code>object</code>: Object causing the exception, can be <code>None</code>.</li> </ul> <p>The default hook formats <code>err_msg</code> and <code>object</code> as: <code>f'{err_msg}: {object!r}'</code>; use “Exception ignored in” error message if <code>err_msg</code> is <code>None</code>.</p> <p><a class="reference internal" href="#sys.unraisablehook" title="sys.unraisablehook"><code>sys.unraisablehook()</code></a> can be overridden to control how unraisable exceptions are handled.</p> <div class="admonition seealso"> <p class="admonition-title">See also</p> <p><a class="reference internal" href="#sys.excepthook" title="sys.excepthook"><code>excepthook()</code></a> which handles uncaught exceptions.</p> </div> <div class="admonition warning"> <p class="admonition-title">Warning</p> <p>Storing <code>exc_value</code> using a custom hook can create a reference cycle. It should be cleared explicitly to break the reference cycle when the exception is no longer needed.</p> <p>Storing <code>object</code> using a custom hook can resurrect it if it is set to an object which is being finalized. Avoid storing <code>object</code> after the custom hook completes to avoid resurrecting objects.</p> </div> <p class="audit-hook"></p> +<p>Raise an auditing event <code>sys.unraisablehook</code> with arguments <em>hook</em>, <em>unraisable</em> when an exception that cannot be handled occurs. The <em>unraisable</em> object is the same as what will be passed to the hook. If no hook has been set, <em>hook</em> may be <code>None</code>.</p> <div class="versionadded"> <p><span class="versionmodified added">New in version 3.8.</span></p> </div> </dd> +</dl> <dl class="py data"> <dt class="sig sig-object py" id="sys.version"> +<code>sys.version</code> </dt> <dd> +<p>A string containing the version number of the Python interpreter plus additional information on the build number and compiler used. This string is displayed when the interactive interpreter is started. Do not extract version information out of it, rather, use <a class="reference internal" href="#sys.version_info" title="sys.version_info"><code>version_info</code></a> and the functions provided by the <a class="reference internal" href="platform#module-platform" title="platform: Retrieves as much platform identifying data as possible."><code>platform</code></a> module.</p> </dd> +</dl> <dl class="py data"> <dt class="sig sig-object py" id="sys.api_version"> +<code>sys.api_version</code> </dt> <dd> +<p>The C API version for this interpreter. Programmers may find this useful when debugging version conflicts between Python and extension modules.</p> </dd> +</dl> <dl class="py data"> <dt class="sig sig-object py" id="sys.version_info"> +<code>sys.version_info</code> </dt> <dd> +<p>A tuple containing the five components of the version number: <em>major</em>, <em>minor</em>, <em>micro</em>, <em>releaselevel</em>, and <em>serial</em>. All values except <em>releaselevel</em> are integers; the release level is <code>'alpha'</code>, <code>'beta'</code>, <code>'candidate'</code>, or <code>'final'</code>. The <code>version_info</code> value corresponding to the Python version 2.0 is <code>(2, 0, 0, 'final', 0)</code>. The components can also be accessed by name, so <code>sys.version_info[0]</code> is equivalent to <code>sys.version_info.major</code> and so on.</p> <div class="versionchanged"> <p><span class="versionmodified changed">Changed in version 3.1: </span>Added named component attributes.</p> </div> </dd> +</dl> <dl class="py data"> <dt class="sig sig-object py" id="sys.warnoptions"> +<code>sys.warnoptions</code> </dt> <dd> +<p>This is an implementation detail of the warnings framework; do not modify this value. Refer to the <a class="reference internal" href="warnings#module-warnings" title="warnings: Issue warning messages and control their disposition."><code>warnings</code></a> module for more information on the warnings framework.</p> </dd> +</dl> <dl class="py data"> <dt class="sig sig-object py" id="sys.winver"> +<code>sys.winver</code> </dt> <dd> +<p>The version number used to form registry keys on Windows platforms. This is stored as string resource 1000 in the Python DLL. The value is normally the 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>sys</code></a> module for informational purposes; modifying this value has no effect on the registry keys used by Python.</p> <div class="availability docutils container"> <p><a class="reference internal" href="https://docs.python.org/3.12/library/intro.html#availability"><span class="std std-ref">Availability</span></a>: Windows.</p> </div> </dd> +</dl> <dl class="py data"> <dt class="sig sig-object py"> <span class="sig-prename descclassname">sys.</span><span class="sig-name descname">monitoring</span> +</dt> <dd> +<p>Namespace containing functions and constants for register callbacks and controlling monitoring events. See <a class="reference internal" href="sys.monitoring#module-sys.monitoring" title="sys.monitoring: Access and control event monitoring"><code>sys.monitoring</code></a> for details.</p> </dd> +</dl> <dl class="py data"> <dt class="sig sig-object py" id="sys._xoptions"> +<code>sys._xoptions</code> </dt> <dd> +<p>A dictionary of the various implementation-specific flags passed through the <a class="reference internal" href="../using/cmdline#cmdoption-X"><code>-X</code></a> command-line option. Option names are either mapped to their values, if given explicitly, or to <a class="reference internal" href="constants#True" title="True"><code>True</code></a>. Example:</p> <pre data-language="shell">$ ./python -Xa=b -Xc +Python 3.2a3+ (py3k, Oct 16 2010, 20:14:50) +[GCC 4.4.3] on linux2 +Type "help", "copyright", "credits" or "license" for more information. +>>> import sys +>>> sys._xoptions +{'a': 'b', 'c': True} +</pre> <div class="impl-detail compound"> <p><strong>CPython implementation detail:</strong> This is a CPython-specific way of accessing options passed through <a class="reference internal" href="../using/cmdline#cmdoption-X"><code>-X</code></a>. Other implementations may export them through other means, or not at all.</p> </div> <div class="versionadded"> <p><span class="versionmodified added">New in version 3.2.</span></p> </div> </dd> +</dl> <h4 class="rubric">Citations</h4> <dl class="citation"> <dt class="label" id="c99"> +<code>C99</code> </dt> <dd> +<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> </dd> </dl> <div class="_attribution"> + <p class="_attribution-p"> + © 2001–2023 Python Software Foundation<br>Licensed under the PSF License.<br> + <a href="https://docs.python.org/3.12/library/sys.html" class="_attribution-link">https://docs.python.org/3.12/library/sys.html</a> + </p> +</div> |
