~dkuhlman/python-training-materials/Materials

« back to all changes in this revision

Viewing changes to python-2.7.12-docs-html/library/sys.html

  • Committer: Dave Kuhlman
  • Date: 2017-04-15 16:24:56 UTC
  • Revision ID: dkuhlman@davekuhlman.org-20170415162456-iav9vozzg4iwqwv3
Updated docs

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
 
2
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 
3
 
 
4
 
 
5
<html xmlns="http://www.w3.org/1999/xhtml">
 
6
  <head>
 
7
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
 
8
    
 
9
    <title>28.1. sys — System-specific parameters and functions &mdash; Python 2.7.12 documentation</title>
 
10
    
 
11
    <link rel="stylesheet" href="../_static/classic.css" type="text/css" />
 
12
    <link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
 
13
    
 
14
    <script type="text/javascript">
 
15
      var DOCUMENTATION_OPTIONS = {
 
16
        URL_ROOT:    '../',
 
17
        VERSION:     '2.7.12',
 
18
        COLLAPSE_INDEX: false,
 
19
        FILE_SUFFIX: '.html',
 
20
        HAS_SOURCE:  true
 
21
      };
 
22
    </script>
 
23
    <script type="text/javascript" src="../_static/jquery.js"></script>
 
24
    <script type="text/javascript" src="../_static/underscore.js"></script>
 
25
    <script type="text/javascript" src="../_static/doctools.js"></script>
 
26
    <script type="text/javascript" src="../_static/sidebar.js"></script>
 
27
    <link rel="search" type="application/opensearchdescription+xml"
 
28
          title="Search within Python 2.7.12 documentation"
 
29
          href="../_static/opensearch.xml"/>
 
30
    <link rel="author" title="About these documents" href="../about.html" />
 
31
    <link rel="copyright" title="Copyright" href="../copyright.html" />
 
32
    <link rel="top" title="Python 2.7.12 documentation" href="../contents.html" />
 
33
    <link rel="up" title="28. Python Runtime Services" href="python.html" />
 
34
    <link rel="next" title="28.2. sysconfig — Provide access to Python’s configuration information" href="sysconfig.html" />
 
35
    <link rel="prev" title="28. Python Runtime Services" href="python.html" />
 
36
    <link rel="shortcut icon" type="image/png" href="../_static/py.png" />
 
37
    <script type="text/javascript" src="../_static/copybutton.js"></script>
 
38
    <script type="text/javascript" src="../_static/version_switch.js"></script>
 
39
 
 
40
    
 
41
 
 
42
  </head>
 
43
  <body role="document">  
 
44
    <div class="related" role="navigation" aria-label="related navigation">
 
45
      <h3>Navigation</h3>
 
46
      <ul>
 
47
        <li class="right" style="margin-right: 10px">
 
48
          <a href="../genindex.html" title="General Index"
 
49
             accesskey="I">index</a></li>
 
50
        <li class="right" >
 
51
          <a href="../py-modindex.html" title="Python Module Index"
 
52
             >modules</a> |</li>
 
53
        <li class="right" >
 
54
          <a href="sysconfig.html" title="28.2. sysconfig — Provide access to Python’s configuration information"
 
55
             accesskey="N">next</a> |</li>
 
56
        <li class="right" >
 
57
          <a href="python.html" title="28. Python Runtime Services"
 
58
             accesskey="P">previous</a> |</li>
 
59
        <li><img src="../_static/py.png" alt=""
 
60
                 style="vertical-align: middle; margin-top: -1px"/></li>
 
61
        <li><a href="https://www.python.org/">Python</a> &raquo;</li>
 
62
        <li>
 
63
          <span class="version_switcher_placeholder">2.7.12</span>
 
64
          <a href="../index.html">Documentation</a> &raquo;
 
65
        </li>
 
66
 
 
67
          <li class="nav-item nav-item-1"><a href="index.html" >The Python Standard Library</a> &raquo;</li>
 
68
          <li class="nav-item nav-item-2"><a href="python.html" accesskey="U">28. Python Runtime Services</a> &raquo;</li> 
 
69
      </ul>
 
70
    </div>    
 
71
 
 
72
    <div class="document">
 
73
      <div class="documentwrapper">
 
74
        <div class="bodywrapper">
 
75
          <div class="body" role="main">
 
76
            
 
77
  <div class="section" id="module-sys">
 
78
<span id="sys-system-specific-parameters-and-functions"></span><h1>28.1. <a class="reference internal" href="#module-sys" title="sys: Access system-specific parameters and functions."><code class="xref py py-mod docutils literal"><span class="pre">sys</span></code></a> &#8212; System-specific parameters and functions<a class="headerlink" href="#module-sys" title="Permalink to this headline">¶</a></h1>
 
79
<p>This module provides access to some variables used or maintained by the
 
80
interpreter and to functions that interact strongly with the interpreter. It is
 
81
always available.</p>
 
82
<dl class="data">
 
83
<dt id="sys.argv">
 
84
<code class="descclassname">sys.</code><code class="descname">argv</code><a class="headerlink" href="#sys.argv" title="Permalink to this definition">¶</a></dt>
 
85
<dd><p>The list of command line arguments passed to a Python script. <code class="docutils literal"><span class="pre">argv[0]</span></code> is the
 
86
script name (it is operating system dependent whether this is a full pathname or
 
87
not).  If the command was executed using the <a class="reference internal" href="../using/cmdline.html#cmdoption-c"><code class="xref std std-option docutils literal"><span class="pre">-c</span></code></a> command line option to
 
88
the interpreter, <code class="docutils literal"><span class="pre">argv[0]</span></code> is set to the string <code class="docutils literal"><span class="pre">'-c'</span></code>.  If no script name
 
89
was passed to the Python interpreter, <code class="docutils literal"><span class="pre">argv[0]</span></code> is the empty string.</p>
 
90
<p>To loop over the standard input, or the list of files given on the
 
91
command line, see the <a class="reference internal" href="fileinput.html#module-fileinput" title="fileinput: Loop over standard input or a list of files."><code class="xref py py-mod docutils literal"><span class="pre">fileinput</span></code></a> module.</p>
 
92
</dd></dl>
 
93
 
 
94
<dl class="data">
 
95
<dt id="sys.byteorder">
 
96
<code class="descclassname">sys.</code><code class="descname">byteorder</code><a class="headerlink" href="#sys.byteorder" title="Permalink to this definition">¶</a></dt>
 
97
<dd><p>An indicator of the native byte order.  This will have the value <code class="docutils literal"><span class="pre">'big'</span></code> on
 
98
big-endian (most-significant byte first) platforms, and <code class="docutils literal"><span class="pre">'little'</span></code> on
 
99
little-endian (least-significant byte first) platforms.</p>
 
100
<div class="versionadded">
 
101
<p><span class="versionmodified">New in version 2.0.</span></p>
 
102
</div>
 
103
</dd></dl>
 
104
 
 
105
<dl class="data">
 
106
<dt id="sys.builtin_module_names">
 
107
<code class="descclassname">sys.</code><code class="descname">builtin_module_names</code><a class="headerlink" href="#sys.builtin_module_names" title="Permalink to this definition">¶</a></dt>
 
108
<dd><p>A tuple of strings giving the names of all modules that are compiled into this
 
109
Python interpreter.  (This information is not available in any other way &#8212;
 
110
<code class="docutils literal"><span class="pre">modules.keys()</span></code> only lists the imported modules.)</p>
 
111
</dd></dl>
 
112
 
 
113
<dl class="function">
 
114
<dt id="sys.call_tracing">
 
115
<code class="descclassname">sys.</code><code class="descname">call_tracing</code><span class="sig-paren">(</span><em>func</em>, <em>args</em><span class="sig-paren">)</span><a class="headerlink" href="#sys.call_tracing" title="Permalink to this definition">¶</a></dt>
 
116
<dd><p>Call <code class="docutils literal"><span class="pre">func(*args)</span></code>, while tracing is enabled.  The tracing state is saved,
 
117
and restored afterwards.  This is intended to be called from a debugger from
 
118
a checkpoint, to recursively debug some other code.</p>
 
119
</dd></dl>
 
120
 
 
121
<dl class="data">
 
122
<dt id="sys.copyright">
 
123
<code class="descclassname">sys.</code><code class="descname">copyright</code><a class="headerlink" href="#sys.copyright" title="Permalink to this definition">¶</a></dt>
 
124
<dd><p>A string containing the copyright pertaining to the Python interpreter.</p>
 
125
</dd></dl>
 
126
 
 
127
<dl class="function">
 
128
<dt id="sys._clear_type_cache">
 
129
<code class="descclassname">sys.</code><code class="descname">_clear_type_cache</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#sys._clear_type_cache" title="Permalink to this definition">¶</a></dt>
 
130
<dd><p>Clear the internal type cache. The type cache is used to speed up attribute
 
131
and method lookups. Use the function <em>only</em> to drop unnecessary references
 
132
during reference leak debugging.</p>
 
133
<p>This function should be used for internal and specialized purposes only.</p>
 
134
<div class="versionadded">
 
135
<p><span class="versionmodified">New in version 2.6.</span></p>
 
136
</div>
 
137
</dd></dl>
 
138
 
 
139
<dl class="function">
 
140
<dt id="sys._current_frames">
 
141
<code class="descclassname">sys.</code><code class="descname">_current_frames</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#sys._current_frames" title="Permalink to this definition">¶</a></dt>
 
142
<dd><p>Return a dictionary mapping each thread&#8217;s identifier to the topmost stack frame
 
143
currently active in that thread at the time the function is called. Note that
 
144
functions in the <a class="reference internal" href="traceback.html#module-traceback" title="traceback: Print or retrieve a stack traceback."><code class="xref py py-mod docutils literal"><span class="pre">traceback</span></code></a> module can build the call stack given such a
 
145
frame.</p>
 
146
<p>This is most useful for debugging deadlock:  this function does not require the
 
147
deadlocked threads&#8217; cooperation, and such threads&#8217; call stacks are frozen for as
 
148
long as they remain deadlocked.  The frame returned for a non-deadlocked thread
 
149
may bear no relationship to that thread&#8217;s current activity by the time calling
 
150
code examines the frame.</p>
 
151
<p>This function should be used for internal and specialized purposes only.</p>
 
152
<div class="versionadded">
 
153
<p><span class="versionmodified">New in version 2.5.</span></p>
 
154
</div>
 
155
</dd></dl>
 
156
 
 
157
<dl class="data">
 
158
<dt id="sys.dllhandle">
 
159
<code class="descclassname">sys.</code><code class="descname">dllhandle</code><a class="headerlink" href="#sys.dllhandle" title="Permalink to this definition">¶</a></dt>
 
160
<dd><p>Integer specifying the handle of the Python DLL. Availability: Windows.</p>
 
161
</dd></dl>
 
162
 
 
163
<dl class="function">
 
164
<dt id="sys.displayhook">
 
165
<code class="descclassname">sys.</code><code class="descname">displayhook</code><span class="sig-paren">(</span><em>value</em><span class="sig-paren">)</span><a class="headerlink" href="#sys.displayhook" title="Permalink to this definition">¶</a></dt>
 
166
<dd><p>If <em>value</em> is not <code class="docutils literal"><span class="pre">None</span></code>, this function prints it to <code class="docutils literal"><span class="pre">sys.stdout</span></code>, and saves
 
167
it in <code class="docutils literal"><span class="pre">__builtin__._</span></code>.</p>
 
168
<p><code class="docutils literal"><span class="pre">sys.displayhook</span></code> is called on the result of evaluating an <a class="reference internal" href="../glossary.html#term-expression"><span class="xref std std-term">expression</span></a>
 
169
entered in an interactive Python session.  The display of these values can be
 
170
customized by assigning another one-argument function to <code class="docutils literal"><span class="pre">sys.displayhook</span></code>.</p>
 
171
</dd></dl>
 
172
 
 
173
<dl class="data">
 
174
<dt id="sys.dont_write_bytecode">
 
175
<code class="descclassname">sys.</code><code class="descname">dont_write_bytecode</code><a class="headerlink" href="#sys.dont_write_bytecode" title="Permalink to this definition">¶</a></dt>
 
176
<dd><p>If this is true, Python won&#8217;t try to write <code class="docutils literal"><span class="pre">.pyc</span></code> or <code class="docutils literal"><span class="pre">.pyo</span></code> files on the
 
177
import of source modules.  This value is initially set to <code class="docutils literal"><span class="pre">True</span></code> or
 
178
<code class="docutils literal"><span class="pre">False</span></code> depending on the <a class="reference internal" href="../using/cmdline.html#cmdoption-B"><code class="xref std std-option docutils literal"><span class="pre">-B</span></code></a> command line option and the
 
179
<span class="target" id="index-0"></span><a class="reference internal" href="../using/cmdline.html#envvar-PYTHONDONTWRITEBYTECODE"><code class="xref std std-envvar docutils literal"><span class="pre">PYTHONDONTWRITEBYTECODE</span></code></a> environment variable, but you can set it
 
180
yourself to control bytecode file generation.</p>
 
181
<div class="versionadded">
 
182
<p><span class="versionmodified">New in version 2.6.</span></p>
 
183
</div>
 
184
</dd></dl>
 
185
 
 
186
<dl class="function">
 
187
<dt id="sys.excepthook">
 
188
<code class="descclassname">sys.</code><code class="descname">excepthook</code><span class="sig-paren">(</span><em>type</em>, <em>value</em>, <em>traceback</em><span class="sig-paren">)</span><a class="headerlink" href="#sys.excepthook" title="Permalink to this definition">¶</a></dt>
 
189
<dd><p>This function prints out a given traceback and exception to <code class="docutils literal"><span class="pre">sys.stderr</span></code>.</p>
 
190
<p>When an exception is raised and uncaught, the interpreter calls
 
191
<code class="docutils literal"><span class="pre">sys.excepthook</span></code> with three arguments, the exception class, exception
 
192
instance, and a traceback object.  In an interactive session this happens just
 
193
before control is returned to the prompt; in a Python program this happens just
 
194
before the program exits.  The handling of such top-level exceptions can be
 
195
customized by assigning another three-argument function to <code class="docutils literal"><span class="pre">sys.excepthook</span></code>.</p>
 
196
</dd></dl>
 
197
 
 
198
<dl class="data">
 
199
<dt id="sys.__displayhook__">
 
200
<code class="descclassname">sys.</code><code class="descname">__displayhook__</code><a class="headerlink" href="#sys.__displayhook__" title="Permalink to this definition">¶</a></dt>
 
201
<dt id="sys.__excepthook__">
 
202
<code class="descclassname">sys.</code><code class="descname">__excepthook__</code><a class="headerlink" href="#sys.__excepthook__" title="Permalink to this definition">¶</a></dt>
 
203
<dd><p>These objects contain the original values of <code class="docutils literal"><span class="pre">displayhook</span></code> and <code class="docutils literal"><span class="pre">excepthook</span></code>
 
204
at the start of the program.  They are saved so that <code class="docutils literal"><span class="pre">displayhook</span></code> and
 
205
<code class="docutils literal"><span class="pre">excepthook</span></code> can be restored in case they happen to get replaced with broken
 
206
objects.</p>
 
207
</dd></dl>
 
208
 
 
209
<dl class="function">
 
210
<dt id="sys.exc_info">
 
211
<code class="descclassname">sys.</code><code class="descname">exc_info</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#sys.exc_info" title="Permalink to this definition">¶</a></dt>
 
212
<dd><p>This function returns a tuple of three values that give information about the
 
213
exception that is currently being handled.  The information returned is specific
 
214
both to the current thread and to the current stack frame.  If the current stack
 
215
frame is not handling an exception, the information is taken from the calling
 
216
stack frame, or its caller, and so on until a stack frame is found that is
 
217
handling an exception.  Here, &#8220;handling an exception&#8221; is defined as &#8220;executing
 
218
or having executed an except clause.&#8221;  For any stack frame, only information
 
219
about the most recently handled exception is accessible.</p>
 
220
<p id="index-1">If no exception is being handled anywhere on the stack, a tuple containing three
 
221
<code class="docutils literal"><span class="pre">None</span></code> values is returned.  Otherwise, the values returned are <code class="docutils literal"><span class="pre">(type,</span> <span class="pre">value,</span>
 
222
<span class="pre">traceback)</span></code>.  Their meaning is: <em>type</em> gets the exception type of the exception
 
223
being handled (a class object); <em>value</em> gets the exception parameter (its
 
224
<em class="dfn">associated value</em> or the second argument to <a class="reference internal" href="../reference/simple_stmts.html#raise"><code class="xref std std-keyword docutils literal"><span class="pre">raise</span></code></a>, which is
 
225
always a class instance if the exception type is a class object); <em>traceback</em>
 
226
gets a traceback object (see the Reference Manual) which encapsulates the call
 
227
stack at the point where the exception originally occurred.</p>
 
228
<p>If <a class="reference internal" href="#sys.exc_clear" title="sys.exc_clear"><code class="xref py py-func docutils literal"><span class="pre">exc_clear()</span></code></a> is called, this function will return three <code class="docutils literal"><span class="pre">None</span></code> values
 
229
until either another exception is raised in the current thread or the execution
 
230
stack returns to a frame where another exception is being handled.</p>
 
231
<div class="admonition warning">
 
232
<p class="first admonition-title">Warning</p>
 
233
<p class="last">Assigning the <em>traceback</em> return value to a local variable in a function that is
 
234
handling an exception will cause a circular reference.  This will prevent
 
235
anything referenced by a local variable in the same function or by the traceback
 
236
from being garbage collected.  Since most functions don&#8217;t need access to the
 
237
traceback, the best solution is to use something like <code class="docutils literal"><span class="pre">exctype,</span> <span class="pre">value</span> <span class="pre">=</span>
 
238
<span class="pre">sys.exc_info()[:2]</span></code> to extract only the exception type and value.  If you do
 
239
need the traceback, make sure to delete it after use (best done with a
 
240
<a class="reference internal" href="../reference/compound_stmts.html#try"><code class="xref std std-keyword docutils literal"><span class="pre">try</span></code></a> ... <a class="reference internal" href="../reference/compound_stmts.html#finally"><code class="xref std std-keyword docutils literal"><span class="pre">finally</span></code></a> statement) or to call <a class="reference internal" href="#sys.exc_info" title="sys.exc_info"><code class="xref py py-func docutils literal"><span class="pre">exc_info()</span></code></a> in
 
241
a function that does not itself handle an exception.</p>
 
242
</div>
 
243
<div class="admonition note">
 
244
<p class="first admonition-title">Note</p>
 
245
<p class="last">Beginning with Python 2.2, such cycles are automatically reclaimed when garbage
 
246
collection is enabled and they become unreachable, but it remains more efficient
 
247
to avoid creating cycles.</p>
 
248
</div>
 
249
</dd></dl>
 
250
 
 
251
<dl class="function">
 
252
<dt id="sys.exc_clear">
 
253
<code class="descclassname">sys.</code><code class="descname">exc_clear</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#sys.exc_clear" title="Permalink to this definition">¶</a></dt>
 
254
<dd><p>This function clears all information relating to the current or last exception
 
255
that occurred in the current thread.  After calling this function,
 
256
<a class="reference internal" href="#sys.exc_info" title="sys.exc_info"><code class="xref py py-func docutils literal"><span class="pre">exc_info()</span></code></a> will return three <code class="docutils literal"><span class="pre">None</span></code> values until another exception is
 
257
raised in the current thread or the execution stack returns to a frame where
 
258
another exception is being handled.</p>
 
259
<p>This function is only needed in only a few obscure situations.  These include
 
260
logging and error handling systems that report information on the last or
 
261
current exception.  This function can also be used to try to free resources and
 
262
trigger object finalization, though no guarantee is made as to what objects will
 
263
be freed, if any.</p>
 
264
<div class="versionadded">
 
265
<p><span class="versionmodified">New in version 2.3.</span></p>
 
266
</div>
 
267
</dd></dl>
 
268
 
 
269
<dl class="data">
 
270
<dt id="sys.exc_type">
 
271
<code class="descclassname">sys.</code><code class="descname">exc_type</code><a class="headerlink" href="#sys.exc_type" title="Permalink to this definition">¶</a></dt>
 
272
<dt id="sys.exc_value">
 
273
<code class="descclassname">sys.</code><code class="descname">exc_value</code><a class="headerlink" href="#sys.exc_value" title="Permalink to this definition">¶</a></dt>
 
274
<dt id="sys.exc_traceback">
 
275
<code class="descclassname">sys.</code><code class="descname">exc_traceback</code><a class="headerlink" href="#sys.exc_traceback" title="Permalink to this definition">¶</a></dt>
 
276
<dd><div class="deprecated">
 
277
<p><span class="versionmodified">Deprecated since version 1.5: </span>Use <a class="reference internal" href="#sys.exc_info" title="sys.exc_info"><code class="xref py py-func docutils literal"><span class="pre">exc_info()</span></code></a> instead.</p>
 
278
</div>
 
279
<p>Since they are global variables, they are not specific to the current thread, so
 
280
their use is not safe in a multi-threaded program.  When no exception is being
 
281
handled, <code class="docutils literal"><span class="pre">exc_type</span></code> is set to <code class="docutils literal"><span class="pre">None</span></code> and the other two are undefined.</p>
 
282
</dd></dl>
 
283
 
 
284
<dl class="data">
 
285
<dt id="sys.exec_prefix">
 
286
<code class="descclassname">sys.</code><code class="descname">exec_prefix</code><a class="headerlink" href="#sys.exec_prefix" title="Permalink to this definition">¶</a></dt>
 
287
<dd><p>A string giving the site-specific directory prefix where the platform-dependent
 
288
Python files are installed; by default, this is also <code class="docutils literal"><span class="pre">'/usr/local'</span></code>.  This can
 
289
be set at build time with the <code class="docutils literal"><span class="pre">--exec-prefix</span></code> argument to the
 
290
<strong class="program">configure</strong> script.  Specifically, all configuration files (e.g. the
 
291
<code class="file docutils literal"><span class="pre">pyconfig.h</span></code> header file) are installed in the directory
 
292
<code class="file docutils literal"><em><span class="pre">exec_prefix</span></em><span class="pre">/lib/python</span><em><span class="pre">X.Y</span></em><span class="pre">/config</span></code>, and shared library modules are
 
293
installed in <code class="file docutils literal"><em><span class="pre">exec_prefix</span></em><span class="pre">/lib/python</span><em><span class="pre">X.Y</span></em><span class="pre">/lib-dynload</span></code>, where <em>X.Y</em>
 
294
is the version number of Python, for example <code class="docutils literal"><span class="pre">2.7</span></code>.</p>
 
295
</dd></dl>
 
296
 
 
297
<dl class="data">
 
298
<dt id="sys.executable">
 
299
<code class="descclassname">sys.</code><code class="descname">executable</code><a class="headerlink" href="#sys.executable" title="Permalink to this definition">¶</a></dt>
 
300
<dd><p>A string giving the absolute path of the executable binary for the Python
 
301
interpreter, on systems where this makes sense. If Python is unable to retrieve
 
302
the real path to its executable, <a class="reference internal" href="#sys.executable" title="sys.executable"><code class="xref py py-data docutils literal"><span class="pre">sys.executable</span></code></a> will be an empty string
 
303
or <code class="docutils literal"><span class="pre">None</span></code>.</p>
 
304
</dd></dl>
 
305
 
 
306
<dl class="function">
 
307
<dt id="sys.exit">
 
308
<code class="descclassname">sys.</code><code class="descname">exit</code><span class="sig-paren">(</span><span class="optional">[</span><em>arg</em><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#sys.exit" title="Permalink to this definition">¶</a></dt>
 
309
<dd><p>Exit from Python.  This is implemented by raising the <a class="reference internal" href="exceptions.html#exceptions.SystemExit" title="exceptions.SystemExit"><code class="xref py py-exc docutils literal"><span class="pre">SystemExit</span></code></a>
 
310
exception, so cleanup actions specified by finally clauses of <a class="reference internal" href="../reference/compound_stmts.html#try"><code class="xref std std-keyword docutils literal"><span class="pre">try</span></code></a>
 
311
statements are honored, and it is possible to intercept the exit attempt at
 
312
an outer level.</p>
 
313
<p>The optional argument <em>arg</em> can be an integer giving the exit status
 
314
(defaulting to zero), or another type of object.  If it is an integer, zero
 
315
is considered &#8220;successful termination&#8221; and any nonzero value is considered
 
316
&#8220;abnormal termination&#8221; by shells and the like.  Most systems require it to be
 
317
in the range 0&#8211;127, and produce undefined results otherwise.  Some systems
 
318
have a convention for assigning specific meanings to specific exit codes, but
 
319
these are generally underdeveloped; Unix programs generally use 2 for command
 
320
line syntax errors and 1 for all other kind of errors.  If another type of
 
321
object is passed, <code class="docutils literal"><span class="pre">None</span></code> is equivalent to passing zero, and any other
 
322
object is printed to <a class="reference internal" href="#sys.stderr" title="sys.stderr"><code class="xref py py-data docutils literal"><span class="pre">stderr</span></code></a> and results in an exit code of 1.  In
 
323
particular, <code class="docutils literal"><span class="pre">sys.exit(&quot;some</span> <span class="pre">error</span> <span class="pre">message&quot;)</span></code> is a quick way to exit a
 
324
program when an error occurs.</p>
 
325
<p>Since <a class="reference internal" href="constants.html#exit" title="exit"><code class="xref py py-func docutils literal"><span class="pre">exit()</span></code></a> ultimately &#8220;only&#8221; raises an exception, it will only exit
 
326
the process when called from the main thread, and the exception is not
 
327
intercepted.</p>
 
328
</dd></dl>
 
329
 
 
330
<dl class="data">
 
331
<dt id="sys.exitfunc">
 
332
<code class="descclassname">sys.</code><code class="descname">exitfunc</code><a class="headerlink" href="#sys.exitfunc" title="Permalink to this definition">¶</a></dt>
 
333
<dd><p>This value is not actually defined by the module, but can be set by the user (or
 
334
by a program) to specify a clean-up action at program exit.  When set, it should
 
335
be a parameterless function.  This function will be called when the interpreter
 
336
exits.  Only one function may be installed in this way; to allow multiple
 
337
functions which will be called at termination, use the <a class="reference internal" href="atexit.html#module-atexit" title="atexit: Register and execute cleanup functions."><code class="xref py py-mod docutils literal"><span class="pre">atexit</span></code></a> module.</p>
 
338
<div class="admonition note">
 
339
<p class="first admonition-title">Note</p>
 
340
<p class="last">The exit function is not called when the program is killed by a signal, when a
 
341
Python fatal internal error is detected, or when <code class="docutils literal"><span class="pre">os._exit()</span></code> is called.</p>
 
342
</div>
 
343
<div class="deprecated">
 
344
<p><span class="versionmodified">Deprecated since version 2.4: </span>Use <a class="reference internal" href="atexit.html#module-atexit" title="atexit: Register and execute cleanup functions."><code class="xref py py-mod docutils literal"><span class="pre">atexit</span></code></a> instead.</p>
 
345
</div>
 
346
</dd></dl>
 
347
 
 
348
<dl class="data">
 
349
<dt id="sys.flags">
 
350
<code class="descclassname">sys.</code><code class="descname">flags</code><a class="headerlink" href="#sys.flags" title="Permalink to this definition">¶</a></dt>
 
351
<dd><p>The struct sequence <em>flags</em> exposes the status of command line flags. The
 
352
attributes are read only.</p>
 
353
<table border="1" class="docutils">
 
354
<colgroup>
 
355
<col width="45%" />
 
356
<col width="55%" />
 
357
</colgroup>
 
358
<thead valign="bottom">
 
359
<tr class="row-odd"><th class="head">attribute</th>
 
360
<th class="head">flag</th>
 
361
</tr>
 
362
</thead>
 
363
<tbody valign="top">
 
364
<tr class="row-even"><td><code class="xref py py-const docutils literal"><span class="pre">debug</span></code></td>
 
365
<td><a class="reference internal" href="../using/cmdline.html#cmdoption-d"><code class="xref std std-option docutils literal"><span class="pre">-d</span></code></a></td>
 
366
</tr>
 
367
<tr class="row-odd"><td><code class="xref py py-const docutils literal"><span class="pre">py3k_warning</span></code></td>
 
368
<td><a class="reference internal" href="../using/cmdline.html#cmdoption-3"><code class="xref std std-option docutils literal"><span class="pre">-3</span></code></a></td>
 
369
</tr>
 
370
<tr class="row-even"><td><code class="xref py py-const docutils literal"><span class="pre">division_warning</span></code></td>
 
371
<td><a class="reference internal" href="../using/cmdline.html#cmdoption-Q"><code class="xref std std-option docutils literal"><span class="pre">-Q</span></code></a></td>
 
372
</tr>
 
373
<tr class="row-odd"><td><code class="xref py py-const docutils literal"><span class="pre">division_new</span></code></td>
 
374
<td><a class="reference internal" href="../using/cmdline.html#cmdoption-Q"><code class="xref std std-option docutils literal"><span class="pre">-Qnew</span></code></a></td>
 
375
</tr>
 
376
<tr class="row-even"><td><a class="reference internal" href="inspect.html#module-inspect" title="inspect: Extract information and source code from live objects."><code class="xref py py-const docutils literal"><span class="pre">inspect</span></code></a></td>
 
377
<td><a class="reference internal" href="../using/cmdline.html#cmdoption-i"><code class="xref std std-option docutils literal"><span class="pre">-i</span></code></a></td>
 
378
</tr>
 
379
<tr class="row-odd"><td><code class="xref py py-const docutils literal"><span class="pre">interactive</span></code></td>
 
380
<td><a class="reference internal" href="../using/cmdline.html#cmdoption-i"><code class="xref std std-option docutils literal"><span class="pre">-i</span></code></a></td>
 
381
</tr>
 
382
<tr class="row-even"><td><code class="xref py py-const docutils literal"><span class="pre">optimize</span></code></td>
 
383
<td><a class="reference internal" href="../using/cmdline.html#cmdoption-O"><code class="xref std std-option docutils literal"><span class="pre">-O</span></code></a> or <a class="reference internal" href="../using/cmdline.html#cmdoption-OO"><code class="xref std std-option docutils literal"><span class="pre">-OO</span></code></a></td>
 
384
</tr>
 
385
<tr class="row-odd"><td><a class="reference internal" href="#sys.dont_write_bytecode" title="sys.dont_write_bytecode"><code class="xref py py-const docutils literal"><span class="pre">dont_write_bytecode</span></code></a></td>
 
386
<td><a class="reference internal" href="../using/cmdline.html#cmdoption-B"><code class="xref std std-option docutils literal"><span class="pre">-B</span></code></a></td>
 
387
</tr>
 
388
<tr class="row-even"><td><code class="xref py py-const docutils literal"><span class="pre">no_user_site</span></code></td>
 
389
<td><a class="reference internal" href="../using/cmdline.html#cmdoption-s"><code class="xref std std-option docutils literal"><span class="pre">-s</span></code></a></td>
 
390
</tr>
 
391
<tr class="row-odd"><td><code class="xref py py-const docutils literal"><span class="pre">no_site</span></code></td>
 
392
<td><a class="reference internal" href="../using/cmdline.html#cmdoption-S"><code class="xref std std-option docutils literal"><span class="pre">-S</span></code></a></td>
 
393
</tr>
 
394
<tr class="row-even"><td><code class="xref py py-const docutils literal"><span class="pre">ignore_environment</span></code></td>
 
395
<td><a class="reference internal" href="../using/cmdline.html#cmdoption-E"><code class="xref std std-option docutils literal"><span class="pre">-E</span></code></a></td>
 
396
</tr>
 
397
<tr class="row-odd"><td><code class="xref py py-const docutils literal"><span class="pre">tabcheck</span></code></td>
 
398
<td><a class="reference internal" href="../using/cmdline.html#cmdoption-t"><code class="xref std std-option docutils literal"><span class="pre">-t</span></code></a> or <a class="reference internal" href="../using/cmdline.html#cmdoption-t"><code class="xref std std-option docutils literal"><span class="pre">-tt</span></code></a></td>
 
399
</tr>
 
400
<tr class="row-even"><td><code class="xref py py-const docutils literal"><span class="pre">verbose</span></code></td>
 
401
<td><a class="reference internal" href="../using/cmdline.html#cmdoption-v"><code class="xref std std-option docutils literal"><span class="pre">-v</span></code></a></td>
 
402
</tr>
 
403
<tr class="row-odd"><td><a class="reference internal" href="functions.html#unicode" title="unicode"><code class="xref py py-const docutils literal"><span class="pre">unicode</span></code></a></td>
 
404
<td><a class="reference internal" href="../using/cmdline.html#cmdoption-U"><code class="xref std std-option docutils literal"><span class="pre">-U</span></code></a></td>
 
405
</tr>
 
406
<tr class="row-even"><td><code class="xref py py-const docutils literal"><span class="pre">bytes_warning</span></code></td>
 
407
<td><code class="xref std std-option docutils literal"><span class="pre">-b</span></code></td>
 
408
</tr>
 
409
<tr class="row-odd"><td><code class="xref py py-const docutils literal"><span class="pre">hash_randomization</span></code></td>
 
410
<td><a class="reference internal" href="../using/cmdline.html#cmdoption-R"><code class="xref std std-option docutils literal"><span class="pre">-R</span></code></a></td>
 
411
</tr>
 
412
</tbody>
 
413
</table>
 
414
<div class="versionadded">
 
415
<p><span class="versionmodified">New in version 2.6.</span></p>
 
416
</div>
 
417
<div class="versionadded">
 
418
<p><span class="versionmodified">New in version 2.7.3: </span>The <code class="docutils literal"><span class="pre">hash_randomization</span></code> attribute.</p>
 
419
</div>
 
420
</dd></dl>
 
421
 
 
422
<dl class="data">
 
423
<dt id="sys.float_info">
 
424
<code class="descclassname">sys.</code><code class="descname">float_info</code><a class="headerlink" href="#sys.float_info" title="Permalink to this definition">¶</a></dt>
 
425
<dd><p>A structseq holding information about the float type. It contains low level
 
426
information about the precision and internal representation.  The values
 
427
correspond to the various floating-point constants defined in the standard
 
428
header file <code class="file docutils literal"><span class="pre">float.h</span></code> for the &#8216;C&#8217; programming language; see section
 
429
5.2.4.2.2 of the 1999 ISO/IEC C standard <a class="reference internal" href="#c99" id="id1">[C99]</a>, &#8216;Characteristics of
 
430
floating types&#8217;, for details.</p>
 
431
<table border="1" class="docutils">
 
432
<colgroup>
 
433
<col width="24%" />
 
434
<col width="18%" />
 
435
<col width="57%" />
 
436
</colgroup>
 
437
<thead valign="bottom">
 
438
<tr class="row-odd"><th class="head">attribute</th>
 
439
<th class="head">float.h macro</th>
 
440
<th class="head">explanation</th>
 
441
</tr>
 
442
</thead>
 
443
<tbody valign="top">
 
444
<tr class="row-even"><td><code class="xref py py-const docutils literal"><span class="pre">epsilon</span></code></td>
 
445
<td>DBL_EPSILON</td>
 
446
<td>difference between 1 and the least value greater
 
447
than 1 that is representable as a float</td>
 
448
</tr>
 
449
<tr class="row-odd"><td><code class="xref py py-const docutils literal"><span class="pre">dig</span></code></td>
 
450
<td>DBL_DIG</td>
 
451
<td>maximum number of decimal digits that can be
 
452
faithfully represented in a float;  see below</td>
 
453
</tr>
 
454
<tr class="row-even"><td><code class="xref py py-const docutils literal"><span class="pre">mant_dig</span></code></td>
 
455
<td>DBL_MANT_DIG</td>
 
456
<td>float precision: the number of base-<code class="docutils literal"><span class="pre">radix</span></code>
 
457
digits in the significand of a float</td>
 
458
</tr>
 
459
<tr class="row-odd"><td><a class="reference internal" href="functions.html#max" title="max"><code class="xref py py-const docutils literal"><span class="pre">max</span></code></a></td>
 
460
<td>DBL_MAX</td>
 
461
<td>maximum representable finite float</td>
 
462
</tr>
 
463
<tr class="row-even"><td><code class="xref py py-const docutils literal"><span class="pre">max_exp</span></code></td>
 
464
<td>DBL_MAX_EXP</td>
 
465
<td>maximum integer e such that <code class="docutils literal"><span class="pre">radix**(e-1)</span></code> is
 
466
a representable finite float</td>
 
467
</tr>
 
468
<tr class="row-odd"><td><code class="xref py py-const docutils literal"><span class="pre">max_10_exp</span></code></td>
 
469
<td>DBL_MAX_10_EXP</td>
 
470
<td>maximum integer e such that <code class="docutils literal"><span class="pre">10**e</span></code> is in the
 
471
range of representable finite floats</td>
 
472
</tr>
 
473
<tr class="row-even"><td><a class="reference internal" href="functions.html#min" title="min"><code class="xref py py-const docutils literal"><span class="pre">min</span></code></a></td>
 
474
<td>DBL_MIN</td>
 
475
<td>minimum positive normalized float</td>
 
476
</tr>
 
477
<tr class="row-odd"><td><code class="xref py py-const docutils literal"><span class="pre">min_exp</span></code></td>
 
478
<td>DBL_MIN_EXP</td>
 
479
<td>minimum integer e such that <code class="docutils literal"><span class="pre">radix**(e-1)</span></code> is
 
480
a normalized float</td>
 
481
</tr>
 
482
<tr class="row-even"><td><code class="xref py py-const docutils literal"><span class="pre">min_10_exp</span></code></td>
 
483
<td>DBL_MIN_10_EXP</td>
 
484
<td>minimum integer e such that <code class="docutils literal"><span class="pre">10**e</span></code> is a
 
485
normalized float</td>
 
486
</tr>
 
487
<tr class="row-odd"><td><code class="xref py py-const docutils literal"><span class="pre">radix</span></code></td>
 
488
<td>FLT_RADIX</td>
 
489
<td>radix of exponent representation</td>
 
490
</tr>
 
491
<tr class="row-even"><td><code class="xref py py-const docutils literal"><span class="pre">rounds</span></code></td>
 
492
<td>FLT_ROUNDS</td>
 
493
<td>integer constant representing the rounding mode
 
494
used for arithmetic operations.  This reflects
 
495
the value of the system FLT_ROUNDS macro at
 
496
interpreter startup time.  See section 5.2.4.2.2
 
497
of the C99 standard for an explanation of the
 
498
possible values and their meanings.</td>
 
499
</tr>
 
500
</tbody>
 
501
</table>
 
502
<p>The attribute <code class="xref py py-attr docutils literal"><span class="pre">sys.float_info.dig</span></code> needs further explanation.  If
 
503
<code class="docutils literal"><span class="pre">s</span></code> is any string representing a decimal number with at most
 
504
<code class="xref py py-attr docutils literal"><span class="pre">sys.float_info.dig</span></code> significant digits, then converting <code class="docutils literal"><span class="pre">s</span></code> to a
 
505
float and back again will recover a string representing the same decimal
 
506
value:</p>
 
507
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">import</span> <span class="nn">sys</span>
 
508
<span class="gp">&gt;&gt;&gt; </span><span class="n">sys</span><span class="o">.</span><span class="n">float_info</span><span class="o">.</span><span class="n">dig</span>
 
509
<span class="go">15</span>
 
510
<span class="gp">&gt;&gt;&gt; </span><span class="n">s</span> <span class="o">=</span> <span class="s1">&#39;3.14159265358979&#39;</span>    <span class="c1"># decimal string with 15 significant digits</span>
 
511
<span class="gp">&gt;&gt;&gt; </span><span class="n">format</span><span class="p">(</span><span class="nb">float</span><span class="p">(</span><span class="n">s</span><span class="p">),</span> <span class="s1">&#39;.15g&#39;</span><span class="p">)</span>  <span class="c1"># convert to float and back -&gt; same value</span>
 
512
<span class="go">&#39;3.14159265358979&#39;</span>
 
513
</pre></div>
 
514
</div>
 
515
<p>But for strings with more than <code class="xref py py-attr docutils literal"><span class="pre">sys.float_info.dig</span></code> significant digits,
 
516
this isn&#8217;t always true:</p>
 
517
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">s</span> <span class="o">=</span> <span class="s1">&#39;9876543211234567&#39;</span>    <span class="c1"># 16 significant digits is too many!</span>
 
518
<span class="gp">&gt;&gt;&gt; </span><span class="n">format</span><span class="p">(</span><span class="nb">float</span><span class="p">(</span><span class="n">s</span><span class="p">),</span> <span class="s1">&#39;.16g&#39;</span><span class="p">)</span>  <span class="c1"># conversion changes value</span>
 
519
<span class="go">&#39;9876543211234568&#39;</span>
 
520
</pre></div>
 
521
</div>
 
522
<div class="versionadded">
 
523
<p><span class="versionmodified">New in version 2.6.</span></p>
 
524
</div>
 
525
</dd></dl>
 
526
 
 
527
<dl class="data">
 
528
<dt id="sys.float_repr_style">
 
529
<code class="descclassname">sys.</code><code class="descname">float_repr_style</code><a class="headerlink" href="#sys.float_repr_style" title="Permalink to this definition">¶</a></dt>
 
530
<dd><p>A string indicating how the <a class="reference internal" href="functions.html#repr" title="repr"><code class="xref py py-func docutils literal"><span class="pre">repr()</span></code></a> function behaves for
 
531
floats.  If the string has value <code class="docutils literal"><span class="pre">'short'</span></code> then for a finite
 
532
float <code class="docutils literal"><span class="pre">x</span></code>, <code class="docutils literal"><span class="pre">repr(x)</span></code> aims to produce a short string with the
 
533
property that <code class="docutils literal"><span class="pre">float(repr(x))</span> <span class="pre">==</span> <span class="pre">x</span></code>.  This is the usual behaviour
 
534
in Python 2.7 and later.  Otherwise, <code class="docutils literal"><span class="pre">float_repr_style</span></code> has value
 
535
<code class="docutils literal"><span class="pre">'legacy'</span></code> and <code class="docutils literal"><span class="pre">repr(x)</span></code> behaves in the same way as it did in
 
536
versions of Python prior to 2.7.</p>
 
537
<div class="versionadded">
 
538
<p><span class="versionmodified">New in version 2.7.</span></p>
 
539
</div>
 
540
</dd></dl>
 
541
 
 
542
<dl class="function">
 
543
<dt id="sys.getcheckinterval">
 
544
<code class="descclassname">sys.</code><code class="descname">getcheckinterval</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#sys.getcheckinterval" title="Permalink to this definition">¶</a></dt>
 
545
<dd><p>Return the interpreter&#8217;s &#8220;check interval&#8221;; see <a class="reference internal" href="#sys.setcheckinterval" title="sys.setcheckinterval"><code class="xref py py-func docutils literal"><span class="pre">setcheckinterval()</span></code></a>.</p>
 
546
<div class="versionadded">
 
547
<p><span class="versionmodified">New in version 2.3.</span></p>
 
548
</div>
 
549
</dd></dl>
 
550
 
 
551
<dl class="function">
 
552
<dt id="sys.getdefaultencoding">
 
553
<code class="descclassname">sys.</code><code class="descname">getdefaultencoding</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#sys.getdefaultencoding" title="Permalink to this definition">¶</a></dt>
 
554
<dd><p>Return the name of the current default string encoding used by the Unicode
 
555
implementation.</p>
 
556
<div class="versionadded">
 
557
<p><span class="versionmodified">New in version 2.0.</span></p>
 
558
</div>
 
559
</dd></dl>
 
560
 
 
561
<dl class="function">
 
562
<dt id="sys.getdlopenflags">
 
563
<code class="descclassname">sys.</code><code class="descname">getdlopenflags</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#sys.getdlopenflags" title="Permalink to this definition">¶</a></dt>
 
564
<dd><p>Return the current value of the flags that are used for <code class="xref c c-func docutils literal"><span class="pre">dlopen()</span></code> calls.
 
565
The flag constants are defined in the <a class="reference internal" href="dl.html#module-dl" title="dl: Call C functions in shared objects. (deprecated) (Unix)"><code class="xref py py-mod docutils literal"><span class="pre">dl</span></code></a> and <code class="xref py py-mod docutils literal"><span class="pre">DLFCN</span></code> modules.
 
566
Availability: Unix.</p>
 
567
<div class="versionadded">
 
568
<p><span class="versionmodified">New in version 2.2.</span></p>
 
569
</div>
 
570
</dd></dl>
 
571
 
 
572
<dl class="function">
 
573
<dt id="sys.getfilesystemencoding">
 
574
<code class="descclassname">sys.</code><code class="descname">getfilesystemencoding</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#sys.getfilesystemencoding" title="Permalink to this definition">¶</a></dt>
 
575
<dd><p>Return the name of the encoding used to convert Unicode filenames into system
 
576
file names, or <code class="docutils literal"><span class="pre">None</span></code> if the system default encoding is used. The result value
 
577
depends on the operating system:</p>
 
578
<ul class="simple">
 
579
<li>On Mac OS X, the encoding is <code class="docutils literal"><span class="pre">'utf-8'</span></code>.</li>
 
580
<li>On Unix, the encoding is the user&#8217;s preference according to the result of
 
581
nl_langinfo(CODESET), or <code class="docutils literal"><span class="pre">None</span></code> if the <code class="docutils literal"><span class="pre">nl_langinfo(CODESET)</span></code>
 
582
failed.</li>
 
583
<li>On Windows NT+, file names are Unicode natively, so no conversion is
 
584
performed. <a class="reference internal" href="#sys.getfilesystemencoding" title="sys.getfilesystemencoding"><code class="xref py py-func docutils literal"><span class="pre">getfilesystemencoding()</span></code></a> still returns <code class="docutils literal"><span class="pre">'mbcs'</span></code>, as
 
585
this is the encoding that applications should use when they explicitly
 
586
want to convert Unicode strings to byte strings that are equivalent when
 
587
used as file names.</li>
 
588
<li>On Windows 9x, the encoding is <code class="docutils literal"><span class="pre">'mbcs'</span></code>.</li>
 
589
</ul>
 
590
<div class="versionadded">
 
591
<p><span class="versionmodified">New in version 2.3.</span></p>
 
592
</div>
 
593
</dd></dl>
 
594
 
 
595
<dl class="function">
 
596
<dt id="sys.getrefcount">
 
597
<code class="descclassname">sys.</code><code class="descname">getrefcount</code><span class="sig-paren">(</span><em>object</em><span class="sig-paren">)</span><a class="headerlink" href="#sys.getrefcount" title="Permalink to this definition">¶</a></dt>
 
598
<dd><p>Return the reference count of the <em>object</em>.  The count returned is generally one
 
599
higher than you might expect, because it includes the (temporary) reference as
 
600
an argument to <a class="reference internal" href="#sys.getrefcount" title="sys.getrefcount"><code class="xref py py-func docutils literal"><span class="pre">getrefcount()</span></code></a>.</p>
 
601
</dd></dl>
 
602
 
 
603
<dl class="function">
 
604
<dt id="sys.getrecursionlimit">
 
605
<code class="descclassname">sys.</code><code class="descname">getrecursionlimit</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#sys.getrecursionlimit" title="Permalink to this definition">¶</a></dt>
 
606
<dd><p>Return the current value of the recursion limit, the maximum depth of the Python
 
607
interpreter stack.  This limit prevents infinite recursion from causing an
 
608
overflow of the C stack and crashing Python.  It can be set by
 
609
<a class="reference internal" href="#sys.setrecursionlimit" title="sys.setrecursionlimit"><code class="xref py py-func docutils literal"><span class="pre">setrecursionlimit()</span></code></a>.</p>
 
610
</dd></dl>
 
611
 
 
612
<dl class="function">
 
613
<dt id="sys.getsizeof">
 
614
<code class="descclassname">sys.</code><code class="descname">getsizeof</code><span class="sig-paren">(</span><em>object</em><span class="optional">[</span>, <em>default</em><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#sys.getsizeof" title="Permalink to this definition">¶</a></dt>
 
615
<dd><p>Return the size of an object in bytes. The object can be any type of
 
616
object. All built-in objects will return correct results, but this
 
617
does not have to hold true for third-party extensions as it is implementation
 
618
specific.</p>
 
619
<p>If given, <em>default</em> will be returned if the object does not provide means to
 
620
retrieve the size.  Otherwise a <a class="reference internal" href="exceptions.html#exceptions.TypeError" title="exceptions.TypeError"><code class="xref py py-exc docutils literal"><span class="pre">TypeError</span></code></a> will be raised.</p>
 
621
<p><a class="reference internal" href="#sys.getsizeof" title="sys.getsizeof"><code class="xref py py-func docutils literal"><span class="pre">getsizeof()</span></code></a> calls the object&#8217;s <code class="docutils literal"><span class="pre">__sizeof__</span></code> method and adds an
 
622
additional garbage collector overhead if the object is managed by the garbage
 
623
collector.</p>
 
624
<div class="versionadded">
 
625
<p><span class="versionmodified">New in version 2.6.</span></p>
 
626
</div>
 
627
</dd></dl>
 
628
 
 
629
<dl class="function">
 
630
<dt id="sys._getframe">
 
631
<code class="descclassname">sys.</code><code class="descname">_getframe</code><span class="sig-paren">(</span><span class="optional">[</span><em>depth</em><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#sys._getframe" title="Permalink to this definition">¶</a></dt>
 
632
<dd><p>Return a frame object from the call stack.  If optional integer <em>depth</em> is
 
633
given, return the frame object that many calls below the top of the stack.  If
 
634
that is deeper than the call stack, <a class="reference internal" href="exceptions.html#exceptions.ValueError" title="exceptions.ValueError"><code class="xref py py-exc docutils literal"><span class="pre">ValueError</span></code></a> is raised.  The default
 
635
for <em>depth</em> is zero, returning the frame at the top of the call stack.</p>
 
636
<div class="impl-detail compound">
 
637
<p><strong>CPython implementation detail:</strong> This function should be used for internal and specialized purposes only.
 
638
It is not guaranteed to exist in all implementations of Python.</p>
 
639
</div>
 
640
</dd></dl>
 
641
 
 
642
<dl class="function">
 
643
<dt id="sys.getprofile">
 
644
<code class="descclassname">sys.</code><code class="descname">getprofile</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#sys.getprofile" title="Permalink to this definition">¶</a></dt>
 
645
<dd><p id="index-2">Get the profiler function as set by <a class="reference internal" href="#sys.setprofile" title="sys.setprofile"><code class="xref py py-func docutils literal"><span class="pre">setprofile()</span></code></a>.</p>
 
646
<div class="versionadded">
 
647
<p><span class="versionmodified">New in version 2.6.</span></p>
 
648
</div>
 
649
</dd></dl>
 
650
 
 
651
<dl class="function">
 
652
<dt id="sys.gettrace">
 
653
<code class="descclassname">sys.</code><code class="descname">gettrace</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#sys.gettrace" title="Permalink to this definition">¶</a></dt>
 
654
<dd><p id="index-3">Get the trace function as set by <a class="reference internal" href="#sys.settrace" title="sys.settrace"><code class="xref py py-func docutils literal"><span class="pre">settrace()</span></code></a>.</p>
 
655
<div class="impl-detail compound">
 
656
<p><strong>CPython implementation detail:</strong> The <a class="reference internal" href="#sys.gettrace" title="sys.gettrace"><code class="xref py py-func docutils literal"><span class="pre">gettrace()</span></code></a> function is intended only for implementing debuggers,
 
657
profilers, coverage tools and the like.  Its behavior is part of the
 
658
implementation platform, rather than part of the language definition, and
 
659
thus may not be available in all Python implementations.</p>
 
660
</div>
 
661
<div class="versionadded">
 
662
<p><span class="versionmodified">New in version 2.6.</span></p>
 
663
</div>
 
664
</dd></dl>
 
665
 
 
666
<dl class="function">
 
667
<dt id="sys.getwindowsversion">
 
668
<code class="descclassname">sys.</code><code class="descname">getwindowsversion</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#sys.getwindowsversion" title="Permalink to this definition">¶</a></dt>
 
669
<dd><p>Return a named tuple describing the Windows version
 
670
currently running.  The named elements are <em>major</em>, <em>minor</em>,
 
671
<em>build</em>, <em>platform</em>, <em>service_pack</em>, <em>service_pack_minor</em>,
 
672
<em>service_pack_major</em>, <em>suite_mask</em>, and <em>product_type</em>.
 
673
<em>service_pack</em> contains a string while all other values are
 
674
integers. The components can also be accessed by name, so
 
675
<code class="docutils literal"><span class="pre">sys.getwindowsversion()[0]</span></code> is equivalent to
 
676
<code class="docutils literal"><span class="pre">sys.getwindowsversion().major</span></code>. For compatibility with prior
 
677
versions, only the first 5 elements are retrievable by indexing.</p>
 
678
<p><em>platform</em> may be one of the following values:</p>
 
679
<table border="1" class="docutils">
 
680
<colgroup>
 
681
<col width="62%" />
 
682
<col width="38%" />
 
683
</colgroup>
 
684
<thead valign="bottom">
 
685
<tr class="row-odd"><th class="head">Constant</th>
 
686
<th class="head">Platform</th>
 
687
</tr>
 
688
</thead>
 
689
<tbody valign="top">
 
690
<tr class="row-even"><td><code class="xref py py-const docutils literal"><span class="pre">0</span> <span class="pre">(VER_PLATFORM_WIN32s)</span></code></td>
 
691
<td>Win32s on Windows 3.1</td>
 
692
</tr>
 
693
<tr class="row-odd"><td><code class="xref py py-const docutils literal"><span class="pre">1</span> <span class="pre">(VER_PLATFORM_WIN32_WINDOWS)</span></code></td>
 
694
<td>Windows 95/98/ME</td>
 
695
</tr>
 
696
<tr class="row-even"><td><code class="xref py py-const docutils literal"><span class="pre">2</span> <span class="pre">(VER_PLATFORM_WIN32_NT)</span></code></td>
 
697
<td>Windows NT/2000/XP/x64</td>
 
698
</tr>
 
699
<tr class="row-odd"><td><code class="xref py py-const docutils literal"><span class="pre">3</span> <span class="pre">(VER_PLATFORM_WIN32_CE)</span></code></td>
 
700
<td>Windows CE</td>
 
701
</tr>
 
702
</tbody>
 
703
</table>
 
704
<p><em>product_type</em> may be one of the following values:</p>
 
705
<table border="1" class="docutils">
 
706
<colgroup>
 
707
<col width="54%" />
 
708
<col width="46%" />
 
709
</colgroup>
 
710
<thead valign="bottom">
 
711
<tr class="row-odd"><th class="head">Constant</th>
 
712
<th class="head">Meaning</th>
 
713
</tr>
 
714
</thead>
 
715
<tbody valign="top">
 
716
<tr class="row-even"><td><code class="xref py py-const docutils literal"><span class="pre">1</span> <span class="pre">(VER_NT_WORKSTATION)</span></code></td>
 
717
<td>The system is a workstation.</td>
 
718
</tr>
 
719
<tr class="row-odd"><td><code class="xref py py-const docutils literal"><span class="pre">2</span> <span class="pre">(VER_NT_DOMAIN_CONTROLLER)</span></code></td>
 
720
<td>The system is a domain
 
721
controller.</td>
 
722
</tr>
 
723
<tr class="row-even"><td><code class="xref py py-const docutils literal"><span class="pre">3</span> <span class="pre">(VER_NT_SERVER)</span></code></td>
 
724
<td>The system is a server, but not
 
725
a domain controller.</td>
 
726
</tr>
 
727
</tbody>
 
728
</table>
 
729
<p>This function wraps the Win32 <code class="xref c c-func docutils literal"><span class="pre">GetVersionEx()</span></code> function; see the
 
730
Microsoft documentation on <code class="xref c c-func docutils literal"><span class="pre">OSVERSIONINFOEX()</span></code> for more information
 
731
about these fields.</p>
 
732
<p>Availability: Windows.</p>
 
733
<div class="versionadded">
 
734
<p><span class="versionmodified">New in version 2.3.</span></p>
 
735
</div>
 
736
<div class="versionchanged">
 
737
<p><span class="versionmodified">Changed in version 2.7: </span>Changed to a named tuple and added <em>service_pack_minor</em>,
 
738
<em>service_pack_major</em>, <em>suite_mask</em>, and <em>product_type</em>.</p>
 
739
</div>
 
740
</dd></dl>
 
741
 
 
742
<dl class="data">
 
743
<dt id="sys.hexversion">
 
744
<code class="descclassname">sys.</code><code class="descname">hexversion</code><a class="headerlink" href="#sys.hexversion" title="Permalink to this definition">¶</a></dt>
 
745
<dd><p>The version number encoded as a single integer.  This is guaranteed to increase
 
746
with each version, including proper support for non-production releases.  For
 
747
example, to test that the Python interpreter is at least version 1.5.2, use:</p>
 
748
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="k">if</span> <span class="n">sys</span><span class="o">.</span><span class="n">hexversion</span> <span class="o">&gt;=</span> <span class="mh">0x010502F0</span><span class="p">:</span>
 
749
    <span class="c1"># use some advanced feature</span>
 
750
    <span class="o">...</span>
 
751
<span class="k">else</span><span class="p">:</span>
 
752
    <span class="c1"># use an alternative implementation or warn the user</span>
 
753
    <span class="o">...</span>
 
754
</pre></div>
 
755
</div>
 
756
<p>This is called <code class="docutils literal"><span class="pre">hexversion</span></code> since it only really looks meaningful when viewed
 
757
as the result of passing it to the built-in <a class="reference internal" href="functions.html#hex" title="hex"><code class="xref py py-func docutils literal"><span class="pre">hex()</span></code></a> function.  The
 
758
<code class="docutils literal"><span class="pre">version_info</span></code> value may be used for a more human-friendly encoding of the
 
759
same information.</p>
 
760
<p>The <code class="docutils literal"><span class="pre">hexversion</span></code> is a 32-bit number with the following layout:</p>
 
761
<table border="1" class="docutils">
 
762
<colgroup>
 
763
<col width="34%" />
 
764
<col width="66%" />
 
765
</colgroup>
 
766
<thead valign="bottom">
 
767
<tr class="row-odd"><th class="head">Bits (big endian order)</th>
 
768
<th class="head">Meaning</th>
 
769
</tr>
 
770
</thead>
 
771
<tbody valign="top">
 
772
<tr class="row-even"><td><code class="xref py py-const docutils literal"><span class="pre">1-8</span></code></td>
 
773
<td><code class="docutils literal"><span class="pre">PY_MAJOR_VERSION</span></code>  (the <code class="docutils literal"><span class="pre">2</span></code> in
 
774
<code class="docutils literal"><span class="pre">2.1.0a3</span></code>)</td>
 
775
</tr>
 
776
<tr class="row-odd"><td><code class="xref py py-const docutils literal"><span class="pre">9-16</span></code></td>
 
777
<td><code class="docutils literal"><span class="pre">PY_MINOR_VERSION</span></code>  (the <code class="docutils literal"><span class="pre">1</span></code> in
 
778
<code class="docutils literal"><span class="pre">2.1.0a3</span></code>)</td>
 
779
</tr>
 
780
<tr class="row-even"><td><code class="xref py py-const docutils literal"><span class="pre">17-24</span></code></td>
 
781
<td><code class="docutils literal"><span class="pre">PY_MICRO_VERSION</span></code>  (the <code class="docutils literal"><span class="pre">0</span></code> in
 
782
<code class="docutils literal"><span class="pre">2.1.0a3</span></code>)</td>
 
783
</tr>
 
784
<tr class="row-odd"><td><code class="xref py py-const docutils literal"><span class="pre">25-28</span></code></td>
 
785
<td><code class="docutils literal"><span class="pre">PY_RELEASE_LEVEL</span></code>  (<code class="docutils literal"><span class="pre">0xA</span></code> for alpha,
 
786
<code class="docutils literal"><span class="pre">0xB</span></code> for beta, <code class="docutils literal"><span class="pre">0xC</span></code> for release
 
787
candidate and <code class="docutils literal"><span class="pre">0xF</span></code> for final)</td>
 
788
</tr>
 
789
<tr class="row-even"><td><code class="xref py py-const docutils literal"><span class="pre">29-32</span></code></td>
 
790
<td><code class="docutils literal"><span class="pre">PY_RELEASE_SERIAL</span></code>  (the <code class="docutils literal"><span class="pre">3</span></code> in
 
791
<code class="docutils literal"><span class="pre">2.1.0a3</span></code>, zero for final releases)</td>
 
792
</tr>
 
793
</tbody>
 
794
</table>
 
795
<p>Thus <code class="docutils literal"><span class="pre">2.1.0a3</span></code> is hexversion <code class="docutils literal"><span class="pre">0x020100a3</span></code>.</p>
 
796
<div class="versionadded">
 
797
<p><span class="versionmodified">New in version 1.5.2.</span></p>
 
798
</div>
 
799
</dd></dl>
 
800
 
 
801
<dl class="data">
 
802
<dt id="sys.long_info">
 
803
<code class="descclassname">sys.</code><code class="descname">long_info</code><a class="headerlink" href="#sys.long_info" title="Permalink to this definition">¶</a></dt>
 
804
<dd><p>A struct sequence that holds information about Python&#8217;s
 
805
internal representation of integers.  The attributes are read only.</p>
 
806
<table border="1" class="docutils">
 
807
<colgroup>
 
808
<col width="35%" />
 
809
<col width="65%" />
 
810
</colgroup>
 
811
<thead valign="bottom">
 
812
<tr class="row-odd"><th class="head">Attribute</th>
 
813
<th class="head">Explanation</th>
 
814
</tr>
 
815
</thead>
 
816
<tbody valign="top">
 
817
<tr class="row-even"><td><code class="xref py py-const docutils literal"><span class="pre">bits_per_digit</span></code></td>
 
818
<td>number of bits held in each digit.  Python
 
819
integers are stored internally in base
 
820
<code class="docutils literal"><span class="pre">2**long_info.bits_per_digit</span></code></td>
 
821
</tr>
 
822
<tr class="row-odd"><td><code class="xref py py-const docutils literal"><span class="pre">sizeof_digit</span></code></td>
 
823
<td>size in bytes of the C type used to
 
824
represent a digit</td>
 
825
</tr>
 
826
</tbody>
 
827
</table>
 
828
<div class="versionadded">
 
829
<p><span class="versionmodified">New in version 2.7.</span></p>
 
830
</div>
 
831
</dd></dl>
 
832
 
 
833
<dl class="data">
 
834
<dt id="sys.last_type">
 
835
<code class="descclassname">sys.</code><code class="descname">last_type</code><a class="headerlink" href="#sys.last_type" title="Permalink to this definition">¶</a></dt>
 
836
<dt id="sys.last_value">
 
837
<code class="descclassname">sys.</code><code class="descname">last_value</code><a class="headerlink" href="#sys.last_value" title="Permalink to this definition">¶</a></dt>
 
838
<dt id="sys.last_traceback">
 
839
<code class="descclassname">sys.</code><code class="descname">last_traceback</code><a class="headerlink" href="#sys.last_traceback" title="Permalink to this definition">¶</a></dt>
 
840
<dd><p>These three variables are not always defined; they are set when an exception is
 
841
not handled and the interpreter prints an error message and a stack traceback.
 
842
Their intended use is to allow an interactive user to import a debugger module
 
843
and engage in post-mortem debugging without having to re-execute the command
 
844
that caused the error.  (Typical use is <code class="docutils literal"><span class="pre">import</span> <span class="pre">pdb;</span> <span class="pre">pdb.pm()</span></code> to enter the
 
845
post-mortem debugger; see chapter <a class="reference internal" href="pdb.html#debugger"><span>pdb &#8212; The Python Debugger</span></a> for
 
846
more information.)</p>
 
847
<p>The meaning of the variables is the same as that of the return values from
 
848
<a class="reference internal" href="#sys.exc_info" title="sys.exc_info"><code class="xref py py-func docutils literal"><span class="pre">exc_info()</span></code></a> above.  (Since there is only one interactive thread,
 
849
thread-safety is not a concern for these variables, unlike for <code class="docutils literal"><span class="pre">exc_type</span></code>
 
850
etc.)</p>
 
851
</dd></dl>
 
852
 
 
853
<dl class="data">
 
854
<dt id="sys.maxint">
 
855
<code class="descclassname">sys.</code><code class="descname">maxint</code><a class="headerlink" href="#sys.maxint" title="Permalink to this definition">¶</a></dt>
 
856
<dd><p>The largest positive integer supported by Python&#8217;s regular integer type.  This
 
857
is at least 2**31-1.  The largest negative integer is <code class="docutils literal"><span class="pre">-maxint-1</span></code> &#8212; the
 
858
asymmetry results from the use of 2&#8217;s complement binary arithmetic.</p>
 
859
</dd></dl>
 
860
 
 
861
<dl class="data">
 
862
<dt id="sys.maxsize">
 
863
<code class="descclassname">sys.</code><code class="descname">maxsize</code><a class="headerlink" href="#sys.maxsize" title="Permalink to this definition">¶</a></dt>
 
864
<dd><p>The largest positive integer supported by the platform&#8217;s Py_ssize_t type,
 
865
and thus the maximum size lists, strings, dicts, and many other containers
 
866
can have.</p>
 
867
</dd></dl>
 
868
 
 
869
<dl class="data">
 
870
<dt id="sys.maxunicode">
 
871
<code class="descclassname">sys.</code><code class="descname">maxunicode</code><a class="headerlink" href="#sys.maxunicode" title="Permalink to this definition">¶</a></dt>
 
872
<dd><p>An integer giving the largest supported code point for a Unicode character.  The
 
873
value of this depends on the configuration option that specifies whether Unicode
 
874
characters are stored as UCS-2 or UCS-4.</p>
 
875
</dd></dl>
 
876
 
 
877
<dl class="data">
 
878
<dt id="sys.meta_path">
 
879
<code class="descclassname">sys.</code><code class="descname">meta_path</code><a class="headerlink" href="#sys.meta_path" title="Permalink to this definition">¶</a></dt>
 
880
<dd><p>A list of <a class="reference internal" href="../glossary.html#term-finder"><span class="xref std std-term">finder</span></a> objects that have their <code class="xref py py-meth docutils literal"><span class="pre">find_module()</span></code>
 
881
methods called to see if one of the objects can find the module to be
 
882
imported. The <code class="xref py py-meth docutils literal"><span class="pre">find_module()</span></code> method is called at least with the
 
883
absolute name of the module being imported. If the module to be imported is
 
884
contained in package then the parent package&#8217;s <code class="xref py py-attr docutils literal"><span class="pre">__path__</span></code> attribute
 
885
is passed in as a second argument. The method returns <code class="docutils literal"><span class="pre">None</span></code> if
 
886
the module cannot be found, else returns a <a class="reference internal" href="../glossary.html#term-loader"><span class="xref std std-term">loader</span></a>.</p>
 
887
<p><a class="reference internal" href="#sys.meta_path" title="sys.meta_path"><code class="xref py py-data docutils literal"><span class="pre">sys.meta_path</span></code></a> is searched before any implicit default finders or
 
888
<a class="reference internal" href="#sys.path" title="sys.path"><code class="xref py py-data docutils literal"><span class="pre">sys.path</span></code></a>.</p>
 
889
<p>See <span class="target" id="index-4"></span><a class="pep reference external" href="https://www.python.org/dev/peps/pep-0302"><strong>PEP 302</strong></a> for the original specification.</p>
 
890
</dd></dl>
 
891
 
 
892
<dl class="data">
 
893
<dt id="sys.modules">
 
894
<code class="descclassname">sys.</code><code class="descname">modules</code><a class="headerlink" href="#sys.modules" title="Permalink to this definition">¶</a></dt>
 
895
<dd><p id="index-5">This is a dictionary that maps module names to modules which have already been
 
896
loaded.  This can be manipulated to force reloading of modules and other tricks.
 
897
Note that removing a module from this dictionary is <em>not</em> the same as calling
 
898
<a class="reference internal" href="functions.html#reload" title="reload"><code class="xref py py-func docutils literal"><span class="pre">reload()</span></code></a> on the corresponding module object.</p>
 
899
</dd></dl>
 
900
 
 
901
<dl class="data">
 
902
<dt id="sys.path">
 
903
<code class="descclassname">sys.</code><code class="descname">path</code><a class="headerlink" href="#sys.path" title="Permalink to this definition">¶</a></dt>
 
904
<dd><p id="index-6">A list of strings that specifies the search path for modules. Initialized from
 
905
the environment variable <span class="target" id="index-7"></span><a class="reference internal" href="../using/cmdline.html#envvar-PYTHONPATH"><code class="xref std std-envvar docutils literal"><span class="pre">PYTHONPATH</span></code></a>, plus an installation-dependent
 
906
default.</p>
 
907
<p>As initialized upon program startup, the first item of this list, <code class="docutils literal"><span class="pre">path[0]</span></code>,
 
908
is the directory containing the script that was used to invoke the Python
 
909
interpreter.  If the script directory is not available (e.g.  if the interpreter
 
910
is invoked interactively or if the script is read from standard input),
 
911
<code class="docutils literal"><span class="pre">path[0]</span></code> is the empty string, which directs Python to search modules in the
 
912
current directory first.  Notice that the script directory is inserted <em>before</em>
 
913
the entries inserted as a result of <span class="target" id="index-8"></span><a class="reference internal" href="../using/cmdline.html#envvar-PYTHONPATH"><code class="xref std std-envvar docutils literal"><span class="pre">PYTHONPATH</span></code></a>.</p>
 
914
<p>A program is free to modify this list for its own purposes.</p>
 
915
<div class="versionchanged">
 
916
<p><span class="versionmodified">Changed in version 2.3: </span>Unicode strings are no longer ignored.</p>
 
917
</div>
 
918
<div class="admonition seealso">
 
919
<p class="first admonition-title">See also</p>
 
920
<p class="last">Module <a class="reference internal" href="site.html#module-site" title="site: Module responsible for site-specific configuration."><code class="xref py py-mod docutils literal"><span class="pre">site</span></code></a> This describes how to use .pth files to extend
 
921
<a class="reference internal" href="#sys.path" title="sys.path"><code class="xref py py-data docutils literal"><span class="pre">sys.path</span></code></a>.</p>
 
922
</div>
 
923
</dd></dl>
 
924
 
 
925
<dl class="data">
 
926
<dt id="sys.path_hooks">
 
927
<code class="descclassname">sys.</code><code class="descname">path_hooks</code><a class="headerlink" href="#sys.path_hooks" title="Permalink to this definition">¶</a></dt>
 
928
<dd><p>A list of callables that take a path argument to try to create a
 
929
<a class="reference internal" href="../glossary.html#term-finder"><span class="xref std std-term">finder</span></a> for the path. If a finder can be created, it is to be
 
930
returned by the callable, else raise <a class="reference internal" href="exceptions.html#exceptions.ImportError" title="exceptions.ImportError"><code class="xref py py-exc docutils literal"><span class="pre">ImportError</span></code></a>.</p>
 
931
<p>Originally specified in <span class="target" id="index-9"></span><a class="pep reference external" href="https://www.python.org/dev/peps/pep-0302"><strong>PEP 302</strong></a>.</p>
 
932
</dd></dl>
 
933
 
 
934
<dl class="data">
 
935
<dt id="sys.path_importer_cache">
 
936
<code class="descclassname">sys.</code><code class="descname">path_importer_cache</code><a class="headerlink" href="#sys.path_importer_cache" title="Permalink to this definition">¶</a></dt>
 
937
<dd><p>A dictionary acting as a cache for <a class="reference internal" href="../glossary.html#term-finder"><span class="xref std std-term">finder</span></a> objects. The keys are
 
938
paths that have been passed to <a class="reference internal" href="#sys.path_hooks" title="sys.path_hooks"><code class="xref py py-data docutils literal"><span class="pre">sys.path_hooks</span></code></a> and the values are
 
939
the finders that are found. If a path is a valid file system path but no
 
940
explicit finder is found on <a class="reference internal" href="#sys.path_hooks" title="sys.path_hooks"><code class="xref py py-data docutils literal"><span class="pre">sys.path_hooks</span></code></a> then <code class="docutils literal"><span class="pre">None</span></code> is
 
941
stored to represent the implicit default finder should be used. If the path
 
942
is not an existing path then <a class="reference internal" href="imp.html#imp.NullImporter" title="imp.NullImporter"><code class="xref py py-class docutils literal"><span class="pre">imp.NullImporter</span></code></a> is set.</p>
 
943
<p>Originally specified in <span class="target" id="index-10"></span><a class="pep reference external" href="https://www.python.org/dev/peps/pep-0302"><strong>PEP 302</strong></a>.</p>
 
944
</dd></dl>
 
945
 
 
946
<dl class="data">
 
947
<dt id="sys.platform">
 
948
<code class="descclassname">sys.</code><code class="descname">platform</code><a class="headerlink" href="#sys.platform" title="Permalink to this definition">¶</a></dt>
 
949
<dd><p>This string contains a platform identifier that can be used to append
 
950
platform-specific components to <a class="reference internal" href="#sys.path" title="sys.path"><code class="xref py py-data docutils literal"><span class="pre">sys.path</span></code></a>, for instance.</p>
 
951
<p>For most Unix systems, this is the lowercased OS name as returned by <code class="docutils literal"><span class="pre">uname</span>
 
952
<span class="pre">-s</span></code> with the first part of the version as returned by <code class="docutils literal"><span class="pre">uname</span> <span class="pre">-r</span></code> appended,
 
953
e.g. <code class="docutils literal"><span class="pre">'sunos5'</span></code>, <em>at the time when Python was built</em>.  Unless you want to
 
954
test for a specific system version, it is therefore recommended to use the
 
955
following idiom:</p>
 
956
<div class="highlight-python"><div class="highlight"><pre><span></span>if sys.platform.startswith(&#39;freebsd&#39;):
 
957
    # FreeBSD-specific code here...
 
958
elif sys.platform.startswith(&#39;linux&#39;):
 
959
    # Linux-specific code here...
 
960
</pre></div>
 
961
</div>
 
962
<div class="versionchanged">
 
963
<p><span class="versionmodified">Changed in version 2.7.3: </span>Since lots of code check for <code class="docutils literal"><span class="pre">sys.platform</span> <span class="pre">==</span> <span class="pre">'linux2'</span></code>, and there is
 
964
no essential change between Linux 2.x and 3.x, <code class="docutils literal"><span class="pre">sys.platform</span></code> is always
 
965
set to <code class="docutils literal"><span class="pre">'linux2'</span></code>, even on Linux 3.x.  In Python 3.3 and later, the
 
966
value will always be set to <code class="docutils literal"><span class="pre">'linux'</span></code>, so it is recommended to always
 
967
use the <code class="docutils literal"><span class="pre">startswith</span></code> idiom presented above.</p>
 
968
</div>
 
969
<p>For other systems, the values are:</p>
 
970
<table border="1" class="docutils">
 
971
<colgroup>
 
972
<col width="44%" />
 
973
<col width="56%" />
 
974
</colgroup>
 
975
<thead valign="bottom">
 
976
<tr class="row-odd"><th class="head">System</th>
 
977
<th class="head"><a class="reference internal" href="platform.html#module-platform" title="platform: Retrieves as much platform identifying data as possible."><code class="xref py py-data docutils literal"><span class="pre">platform</span></code></a> value</th>
 
978
</tr>
 
979
</thead>
 
980
<tbody valign="top">
 
981
<tr class="row-even"><td>Linux (2.x <em>and</em> 3.x)</td>
 
982
<td><code class="docutils literal"><span class="pre">'linux2'</span></code></td>
 
983
</tr>
 
984
<tr class="row-odd"><td>Windows</td>
 
985
<td><code class="docutils literal"><span class="pre">'win32'</span></code></td>
 
986
</tr>
 
987
<tr class="row-even"><td>Windows/Cygwin</td>
 
988
<td><code class="docutils literal"><span class="pre">'cygwin'</span></code></td>
 
989
</tr>
 
990
<tr class="row-odd"><td>Mac OS X</td>
 
991
<td><code class="docutils literal"><span class="pre">'darwin'</span></code></td>
 
992
</tr>
 
993
<tr class="row-even"><td>OS/2</td>
 
994
<td><code class="docutils literal"><span class="pre">'os2'</span></code></td>
 
995
</tr>
 
996
<tr class="row-odd"><td>OS/2 EMX</td>
 
997
<td><code class="docutils literal"><span class="pre">'os2emx'</span></code></td>
 
998
</tr>
 
999
<tr class="row-even"><td>RiscOS</td>
 
1000
<td><code class="docutils literal"><span class="pre">'riscos'</span></code></td>
 
1001
</tr>
 
1002
<tr class="row-odd"><td>AtheOS</td>
 
1003
<td><code class="docutils literal"><span class="pre">'atheos'</span></code></td>
 
1004
</tr>
 
1005
</tbody>
 
1006
</table>
 
1007
<div class="admonition seealso">
 
1008
<p class="first admonition-title">See also</p>
 
1009
<p><a class="reference internal" href="os.html#os.name" title="os.name"><code class="xref py py-attr docutils literal"><span class="pre">os.name</span></code></a> has a coarser granularity.  <a class="reference internal" href="os.html#os.uname" title="os.uname"><code class="xref py py-func docutils literal"><span class="pre">os.uname()</span></code></a> gives
 
1010
system-dependent version information.</p>
 
1011
<p class="last">The <a class="reference internal" href="platform.html#module-platform" title="platform: Retrieves as much platform identifying data as possible."><code class="xref py py-mod docutils literal"><span class="pre">platform</span></code></a> module provides detailed checks for the
 
1012
system&#8217;s identity.</p>
 
1013
</div>
 
1014
</dd></dl>
 
1015
 
 
1016
<dl class="data">
 
1017
<dt id="sys.prefix">
 
1018
<code class="descclassname">sys.</code><code class="descname">prefix</code><a class="headerlink" href="#sys.prefix" title="Permalink to this definition">¶</a></dt>
 
1019
<dd><p>A string giving the site-specific directory prefix where the platform
 
1020
independent Python files are installed; by default, this is the string
 
1021
<code class="docutils literal"><span class="pre">'/usr/local'</span></code>.  This can be set at build time with the <code class="docutils literal"><span class="pre">--prefix</span></code>
 
1022
argument to the <strong class="program">configure</strong> script.  The main collection of Python
 
1023
library modules is installed in the directory <code class="file docutils literal"><em><span class="pre">prefix</span></em><span class="pre">/lib/python</span><em><span class="pre">X.Y</span></em></code>
 
1024
while the platform independent header files (all except <code class="file docutils literal"><span class="pre">pyconfig.h</span></code>) are
 
1025
stored in <code class="file docutils literal"><em><span class="pre">prefix</span></em><span class="pre">/include/python</span><em><span class="pre">X.Y</span></em></code>, where <em>X.Y</em> is the version
 
1026
number of Python, for example <code class="docutils literal"><span class="pre">2.7</span></code>.</p>
 
1027
</dd></dl>
 
1028
 
 
1029
<dl class="data">
 
1030
<dt id="sys.ps1">
 
1031
<code class="descclassname">sys.</code><code class="descname">ps1</code><a class="headerlink" href="#sys.ps1" title="Permalink to this definition">¶</a></dt>
 
1032
<dt id="sys.ps2">
 
1033
<code class="descclassname">sys.</code><code class="descname">ps2</code><a class="headerlink" href="#sys.ps2" title="Permalink to this definition">¶</a></dt>
 
1034
<dd><p id="index-11">Strings specifying the primary and secondary prompt of the interpreter.  These
 
1035
are only defined if the interpreter is in interactive mode.  Their initial
 
1036
values in this case are <code class="docutils literal"><span class="pre">'&gt;&gt;&gt;</span> <span class="pre">'</span></code> and <code class="docutils literal"><span class="pre">'...</span> <span class="pre">'</span></code>.  If a non-string object is
 
1037
assigned to either variable, its <a class="reference internal" href="functions.html#str" title="str"><code class="xref py py-func docutils literal"><span class="pre">str()</span></code></a> is re-evaluated each time the
 
1038
interpreter prepares to read a new interactive command; this can be used to
 
1039
implement a dynamic prompt.</p>
 
1040
</dd></dl>
 
1041
 
 
1042
<dl class="data">
 
1043
<dt id="sys.py3kwarning">
 
1044
<code class="descclassname">sys.</code><code class="descname">py3kwarning</code><a class="headerlink" href="#sys.py3kwarning" title="Permalink to this definition">¶</a></dt>
 
1045
<dd><p>Bool containing the status of the Python 3 warning flag. It&#8217;s <code class="docutils literal"><span class="pre">True</span></code>
 
1046
when Python is started with the -3 option.  (This should be considered
 
1047
read-only; setting it to a different value doesn&#8217;t have an effect on
 
1048
Python 3 warnings.)</p>
 
1049
<div class="versionadded">
 
1050
<p><span class="versionmodified">New in version 2.6.</span></p>
 
1051
</div>
 
1052
</dd></dl>
 
1053
 
 
1054
<dl class="function">
 
1055
<dt id="sys.setcheckinterval">
 
1056
<code class="descclassname">sys.</code><code class="descname">setcheckinterval</code><span class="sig-paren">(</span><em>interval</em><span class="sig-paren">)</span><a class="headerlink" href="#sys.setcheckinterval" title="Permalink to this definition">¶</a></dt>
 
1057
<dd><p>Set the interpreter&#8217;s &#8220;check interval&#8221;.  This integer value determines how often
 
1058
the interpreter checks for periodic things such as thread switches and signal
 
1059
handlers.  The default is <code class="docutils literal"><span class="pre">100</span></code>, meaning the check is performed every 100
 
1060
Python virtual instructions. Setting it to a larger value may increase
 
1061
performance for programs using threads.  Setting it to a value <code class="docutils literal"><span class="pre">&lt;=</span></code> 0 checks
 
1062
every virtual instruction, maximizing responsiveness as well as overhead.</p>
 
1063
</dd></dl>
 
1064
 
 
1065
<dl class="function">
 
1066
<dt id="sys.setdefaultencoding">
 
1067
<code class="descclassname">sys.</code><code class="descname">setdefaultencoding</code><span class="sig-paren">(</span><em>name</em><span class="sig-paren">)</span><a class="headerlink" href="#sys.setdefaultencoding" title="Permalink to this definition">¶</a></dt>
 
1068
<dd><p>Set the current default string encoding used by the Unicode implementation.  If
 
1069
<em>name</em> does not match any available encoding, <a class="reference internal" href="exceptions.html#exceptions.LookupError" title="exceptions.LookupError"><code class="xref py py-exc docutils literal"><span class="pre">LookupError</span></code></a> is raised.
 
1070
This function is only intended to be used by the <a class="reference internal" href="site.html#module-site" title="site: Module responsible for site-specific configuration."><code class="xref py py-mod docutils literal"><span class="pre">site</span></code></a> module
 
1071
implementation and, where needed, by <code class="xref py py-mod docutils literal"><span class="pre">sitecustomize</span></code>.  Once used by the
 
1072
<a class="reference internal" href="site.html#module-site" title="site: Module responsible for site-specific configuration."><code class="xref py py-mod docutils literal"><span class="pre">site</span></code></a> module, it is removed from the <a class="reference internal" href="#module-sys" title="sys: Access system-specific parameters and functions."><code class="xref py py-mod docutils literal"><span class="pre">sys</span></code></a> module&#8217;s namespace.</p>
 
1073
<div class="versionadded">
 
1074
<p><span class="versionmodified">New in version 2.0.</span></p>
 
1075
</div>
 
1076
</dd></dl>
 
1077
 
 
1078
<dl class="function">
 
1079
<dt id="sys.setdlopenflags">
 
1080
<code class="descclassname">sys.</code><code class="descname">setdlopenflags</code><span class="sig-paren">(</span><em>n</em><span class="sig-paren">)</span><a class="headerlink" href="#sys.setdlopenflags" title="Permalink to this definition">¶</a></dt>
 
1081
<dd><p>Set the flags used by the interpreter for <code class="xref c c-func docutils literal"><span class="pre">dlopen()</span></code> calls, such as when
 
1082
the interpreter loads extension modules.  Among other things, this will enable a
 
1083
lazy resolving of symbols when importing a module, if called as
 
1084
<code class="docutils literal"><span class="pre">sys.setdlopenflags(0)</span></code>.  To share symbols across extension modules, call as
 
1085
<code class="docutils literal"><span class="pre">sys.setdlopenflags(dl.RTLD_NOW</span> <span class="pre">|</span> <span class="pre">dl.RTLD_GLOBAL)</span></code>.  Symbolic names for the
 
1086
flag modules can be either found in the <a class="reference internal" href="dl.html#module-dl" title="dl: Call C functions in shared objects. (deprecated) (Unix)"><code class="xref py py-mod docutils literal"><span class="pre">dl</span></code></a> module, or in the <code class="xref py py-mod docutils literal"><span class="pre">DLFCN</span></code>
 
1087
module. If <code class="xref py py-mod docutils literal"><span class="pre">DLFCN</span></code> is not available, it can be generated from
 
1088
<code class="file docutils literal"><span class="pre">/usr/include/dlfcn.h</span></code> using the <strong class="program">h2py</strong> script. Availability:
 
1089
Unix.</p>
 
1090
<div class="versionadded">
 
1091
<p><span class="versionmodified">New in version 2.2.</span></p>
 
1092
</div>
 
1093
</dd></dl>
 
1094
 
 
1095
<dl class="function">
 
1096
<dt id="sys.setprofile">
 
1097
<code class="descclassname">sys.</code><code class="descname">setprofile</code><span class="sig-paren">(</span><em>profilefunc</em><span class="sig-paren">)</span><a class="headerlink" href="#sys.setprofile" title="Permalink to this definition">¶</a></dt>
 
1098
<dd><p id="index-12">Set the system&#8217;s profile function, which allows you to implement a Python source
 
1099
code profiler in Python.  See chapter <a class="reference internal" href="profile.html#profile"><span>The Python Profilers</span></a> for more information on the
 
1100
Python profiler.  The system&#8217;s profile function is called similarly to the
 
1101
system&#8217;s trace function (see <a class="reference internal" href="#sys.settrace" title="sys.settrace"><code class="xref py py-func docutils literal"><span class="pre">settrace()</span></code></a>), but it isn&#8217;t called for each
 
1102
executed line of code (only on call and return, but the return event is reported
 
1103
even when an exception has been set).  The function is thread-specific, but
 
1104
there is no way for the profiler to know about context switches between threads,
 
1105
so it does not make sense to use this in the presence of multiple threads. Also,
 
1106
its return value is not used, so it can simply return <code class="docutils literal"><span class="pre">None</span></code>.</p>
 
1107
</dd></dl>
 
1108
 
 
1109
<dl class="function">
 
1110
<dt id="sys.setrecursionlimit">
 
1111
<code class="descclassname">sys.</code><code class="descname">setrecursionlimit</code><span class="sig-paren">(</span><em>limit</em><span class="sig-paren">)</span><a class="headerlink" href="#sys.setrecursionlimit" title="Permalink to this definition">¶</a></dt>
 
1112
<dd><p>Set the maximum depth of the Python interpreter stack to <em>limit</em>.  This limit
 
1113
prevents infinite recursion from causing an overflow of the C stack and crashing
 
1114
Python.</p>
 
1115
<p>The highest possible limit is platform-dependent.  A user may need to set the
 
1116
limit higher when she has a program that requires deep recursion and a platform
 
1117
that supports a higher limit.  This should be done with care, because a too-high
 
1118
limit can lead to a crash.</p>
 
1119
</dd></dl>
 
1120
 
 
1121
<dl class="function">
 
1122
<dt id="sys.settrace">
 
1123
<code class="descclassname">sys.</code><code class="descname">settrace</code><span class="sig-paren">(</span><em>tracefunc</em><span class="sig-paren">)</span><a class="headerlink" href="#sys.settrace" title="Permalink to this definition">¶</a></dt>
 
1124
<dd><p id="index-13">Set the system&#8217;s trace function, which allows you to implement a Python
 
1125
source code debugger in Python.  The function is thread-specific; for a
 
1126
debugger to support multiple threads, it must be registered using
 
1127
<a class="reference internal" href="#sys.settrace" title="sys.settrace"><code class="xref py py-func docutils literal"><span class="pre">settrace()</span></code></a> for each thread being debugged.</p>
 
1128
<p>Trace functions should have three arguments: <em>frame</em>, <em>event</em>, and
 
1129
<em>arg</em>. <em>frame</em> is the current stack frame.  <em>event</em> is a string: <code class="docutils literal"><span class="pre">'call'</span></code>,
 
1130
<code class="docutils literal"><span class="pre">'line'</span></code>, <code class="docutils literal"><span class="pre">'return'</span></code>, <code class="docutils literal"><span class="pre">'exception'</span></code>, <code class="docutils literal"><span class="pre">'c_call'</span></code>, <code class="docutils literal"><span class="pre">'c_return'</span></code>, or
 
1131
<code class="docutils literal"><span class="pre">'c_exception'</span></code>. <em>arg</em> depends on the event type.</p>
 
1132
<p>The trace function is invoked (with <em>event</em> set to <code class="docutils literal"><span class="pre">'call'</span></code>) whenever a new
 
1133
local scope is entered; it should return a reference to a local trace
 
1134
function to be used that scope, or <code class="docutils literal"><span class="pre">None</span></code> if the scope shouldn&#8217;t be traced.</p>
 
1135
<p>The local trace function should return a reference to itself (or to another
 
1136
function for further tracing in that scope), or <code class="docutils literal"><span class="pre">None</span></code> to turn off tracing
 
1137
in that scope.</p>
 
1138
<p>The events have the following meaning:</p>
 
1139
<dl class="docutils">
 
1140
<dt><code class="docutils literal"><span class="pre">'call'</span></code></dt>
 
1141
<dd>A function is called (or some other code block entered).  The
 
1142
global trace function is called; <em>arg</em> is <code class="docutils literal"><span class="pre">None</span></code>; the return value
 
1143
specifies the local trace function.</dd>
 
1144
<dt><code class="docutils literal"><span class="pre">'line'</span></code></dt>
 
1145
<dd>The interpreter is about to execute a new line of code or re-execute the
 
1146
condition of a loop.  The local trace function is called; <em>arg</em> is
 
1147
<code class="docutils literal"><span class="pre">None</span></code>; the return value specifies the new local trace function.  See
 
1148
<code class="file docutils literal"><span class="pre">Objects/lnotab_notes.txt</span></code> for a detailed explanation of how this
 
1149
works.</dd>
 
1150
<dt><code class="docutils literal"><span class="pre">'return'</span></code></dt>
 
1151
<dd>A function (or other code block) is about to return.  The local trace
 
1152
function is called; <em>arg</em> is the value that will be returned, or <code class="docutils literal"><span class="pre">None</span></code>
 
1153
if the event is caused by an exception being raised.  The trace function&#8217;s
 
1154
return value is ignored.</dd>
 
1155
<dt><code class="docutils literal"><span class="pre">'exception'</span></code></dt>
 
1156
<dd>An exception has occurred.  The local trace function is called; <em>arg</em> is a
 
1157
tuple <code class="docutils literal"><span class="pre">(exception,</span> <span class="pre">value,</span> <span class="pre">traceback)</span></code>; the return value specifies the
 
1158
new local trace function.</dd>
 
1159
<dt><code class="docutils literal"><span class="pre">'c_call'</span></code></dt>
 
1160
<dd>A C function is about to be called.  This may be an extension function or
 
1161
a built-in.  <em>arg</em> is the C function object.</dd>
 
1162
<dt><code class="docutils literal"><span class="pre">'c_return'</span></code></dt>
 
1163
<dd>A C function has returned. <em>arg</em> is the C function object.</dd>
 
1164
<dt><code class="docutils literal"><span class="pre">'c_exception'</span></code></dt>
 
1165
<dd>A C function has raised an exception.  <em>arg</em> is the C function object.</dd>
 
1166
</dl>
 
1167
<p>Note that as an exception is propagated down the chain of callers, an
 
1168
<code class="docutils literal"><span class="pre">'exception'</span></code> event is generated at each level.</p>
 
1169
<p>For more information on code and frame objects, refer to <a class="reference internal" href="../reference/datamodel.html#types"><span>The standard type hierarchy</span></a>.</p>
 
1170
<div class="impl-detail compound">
 
1171
<p><strong>CPython implementation detail:</strong> The <a class="reference internal" href="#sys.settrace" title="sys.settrace"><code class="xref py py-func docutils literal"><span class="pre">settrace()</span></code></a> function is intended only for implementing debuggers,
 
1172
profilers, coverage tools and the like.  Its behavior is part of the
 
1173
implementation platform, rather than part of the language definition, and
 
1174
thus may not be available in all Python implementations.</p>
 
1175
</div>
 
1176
</dd></dl>
 
1177
 
 
1178
<dl class="function">
 
1179
<dt id="sys.settscdump">
 
1180
<code class="descclassname">sys.</code><code class="descname">settscdump</code><span class="sig-paren">(</span><em>on_flag</em><span class="sig-paren">)</span><a class="headerlink" href="#sys.settscdump" title="Permalink to this definition">¶</a></dt>
 
1181
<dd><p>Activate dumping of VM measurements using the Pentium timestamp counter, if
 
1182
<em>on_flag</em> is true. Deactivate these dumps if <em>on_flag</em> is off. The function is
 
1183
available only if Python was compiled with <code class="docutils literal"><span class="pre">--with-tsc</span></code>. To understand
 
1184
the output of this dump, read <code class="file docutils literal"><span class="pre">Python/ceval.c</span></code> in the Python sources.</p>
 
1185
<div class="versionadded">
 
1186
<p><span class="versionmodified">New in version 2.4.</span></p>
 
1187
</div>
 
1188
<div class="impl-detail compound">
 
1189
<p><strong>CPython implementation detail:</strong> This function is intimately bound to CPython implementation details and
 
1190
thus not likely to be implemented elsewhere.</p>
 
1191
</div>
 
1192
</dd></dl>
 
1193
 
 
1194
<dl class="data">
 
1195
<dt id="sys.stdin">
 
1196
<code class="descclassname">sys.</code><code class="descname">stdin</code><a class="headerlink" href="#sys.stdin" title="Permalink to this definition">¶</a></dt>
 
1197
<dt id="sys.stdout">
 
1198
<code class="descclassname">sys.</code><code class="descname">stdout</code><a class="headerlink" href="#sys.stdout" title="Permalink to this definition">¶</a></dt>
 
1199
<dt id="sys.stderr">
 
1200
<code class="descclassname">sys.</code><code class="descname">stderr</code><a class="headerlink" href="#sys.stderr" title="Permalink to this definition">¶</a></dt>
 
1201
<dd><p id="index-14">File objects corresponding to the interpreter&#8217;s standard input, output and error
 
1202
streams.  <code class="docutils literal"><span class="pre">stdin</span></code> is used for all interpreter input except for scripts but
 
1203
including calls to <a class="reference internal" href="functions.html#input" title="input"><code class="xref py py-func docutils literal"><span class="pre">input()</span></code></a> and <a class="reference internal" href="functions.html#raw_input" title="raw_input"><code class="xref py py-func docutils literal"><span class="pre">raw_input()</span></code></a>.  <code class="docutils literal"><span class="pre">stdout</span></code> is used for
 
1204
the output of <a class="reference internal" href="../reference/simple_stmts.html#print"><code class="xref std std-keyword docutils literal"><span class="pre">print</span></code></a> and <a class="reference internal" href="../glossary.html#term-expression"><span class="xref std std-term">expression</span></a> statements and for the
 
1205
prompts of <a class="reference internal" href="functions.html#input" title="input"><code class="xref py py-func docutils literal"><span class="pre">input()</span></code></a> and <a class="reference internal" href="functions.html#raw_input" title="raw_input"><code class="xref py py-func docutils literal"><span class="pre">raw_input()</span></code></a>. The interpreter&#8217;s own prompts
 
1206
and (almost all of) its error messages go to <code class="docutils literal"><span class="pre">stderr</span></code>.  <code class="docutils literal"><span class="pre">stdout</span></code> and
 
1207
<code class="docutils literal"><span class="pre">stderr</span></code> needn&#8217;t be built-in file objects: any object is acceptable as long
 
1208
as it has a <code class="xref py py-meth docutils literal"><span class="pre">write()</span></code> method that takes a string argument.  (Changing these
 
1209
objects doesn&#8217;t affect the standard I/O streams of processes executed by
 
1210
<a class="reference internal" href="os.html#os.popen" title="os.popen"><code class="xref py py-func docutils literal"><span class="pre">os.popen()</span></code></a>, <a class="reference internal" href="os.html#os.system" title="os.system"><code class="xref py py-func docutils literal"><span class="pre">os.system()</span></code></a> or the <code class="xref py py-func docutils literal"><span class="pre">exec*()</span></code> family of functions in
 
1211
the <a class="reference internal" href="os.html#module-os" title="os: Miscellaneous operating system interfaces."><code class="xref py py-mod docutils literal"><span class="pre">os</span></code></a> module.)</p>
 
1212
</dd></dl>
 
1213
 
 
1214
<dl class="data">
 
1215
<dt id="sys.__stdin__">
 
1216
<code class="descclassname">sys.</code><code class="descname">__stdin__</code><a class="headerlink" href="#sys.__stdin__" title="Permalink to this definition">¶</a></dt>
 
1217
<dt id="sys.__stdout__">
 
1218
<code class="descclassname">sys.</code><code class="descname">__stdout__</code><a class="headerlink" href="#sys.__stdout__" title="Permalink to this definition">¶</a></dt>
 
1219
<dt id="sys.__stderr__">
 
1220
<code class="descclassname">sys.</code><code class="descname">__stderr__</code><a class="headerlink" href="#sys.__stderr__" title="Permalink to this definition">¶</a></dt>
 
1221
<dd><p>These objects contain the original values of <code class="docutils literal"><span class="pre">stdin</span></code>, <code class="docutils literal"><span class="pre">stderr</span></code> and
 
1222
<code class="docutils literal"><span class="pre">stdout</span></code> at the start of the program.  They are used during finalization,
 
1223
and could be useful to print to the actual standard stream no matter if the
 
1224
<code class="docutils literal"><span class="pre">sys.std*</span></code> object has been redirected.</p>
 
1225
<p>It can also be used to restore the actual files to known working file objects
 
1226
in case they have been overwritten with a broken object.  However, the
 
1227
preferred way to do this is to explicitly save the previous stream before
 
1228
replacing it, and restore the saved object.</p>
 
1229
</dd></dl>
 
1230
 
 
1231
<dl class="data">
 
1232
<dt id="sys.subversion">
 
1233
<code class="descclassname">sys.</code><code class="descname">subversion</code><a class="headerlink" href="#sys.subversion" title="Permalink to this definition">¶</a></dt>
 
1234
<dd><p>A triple (repo, branch, version) representing the Subversion information of the
 
1235
Python interpreter. <em>repo</em> is the name of the repository, <code class="docutils literal"><span class="pre">'CPython'</span></code>.
 
1236
<em>branch</em> is a string of one of the forms <code class="docutils literal"><span class="pre">'trunk'</span></code>, <code class="docutils literal"><span class="pre">'branches/name'</span></code> or
 
1237
<code class="docutils literal"><span class="pre">'tags/name'</span></code>. <em>version</em> is the output of <code class="docutils literal"><span class="pre">svnversion</span></code>, if the interpreter
 
1238
was built from a Subversion checkout; it contains the revision number (range)
 
1239
and possibly a trailing &#8216;M&#8217; if there were local modifications. If the tree was
 
1240
exported (or svnversion was not available), it is the revision of
 
1241
<code class="docutils literal"><span class="pre">Include/patchlevel.h</span></code> if the branch is a tag. Otherwise, it is <code class="docutils literal"><span class="pre">None</span></code>.</p>
 
1242
<div class="versionadded">
 
1243
<p><span class="versionmodified">New in version 2.5.</span></p>
 
1244
</div>
 
1245
<div class="admonition note">
 
1246
<p class="first admonition-title">Note</p>
 
1247
<p class="last">Python is now <a class="reference external" href="https://docs.python.org/devguide/">developed</a> using
 
1248
Mercurial.  In recent Python 2.7 bugfix releases, <a class="reference internal" href="#sys.subversion" title="sys.subversion"><code class="xref py py-data docutils literal"><span class="pre">subversion</span></code></a>
 
1249
therefore contains placeholder information.  It is removed in Python
 
1250
3.3.</p>
 
1251
</div>
 
1252
</dd></dl>
 
1253
 
 
1254
<dl class="data">
 
1255
<dt id="sys.tracebacklimit">
 
1256
<code class="descclassname">sys.</code><code class="descname">tracebacklimit</code><a class="headerlink" href="#sys.tracebacklimit" title="Permalink to this definition">¶</a></dt>
 
1257
<dd><p>When this variable is set to an integer value, it determines the maximum number
 
1258
of levels of traceback information printed when an unhandled exception occurs.
 
1259
The default is <code class="docutils literal"><span class="pre">1000</span></code>.  When set to <code class="docutils literal"><span class="pre">0</span></code> or less, all traceback information
 
1260
is suppressed and only the exception type and value are printed.</p>
 
1261
</dd></dl>
 
1262
 
 
1263
<dl class="data">
 
1264
<dt id="sys.version">
 
1265
<code class="descclassname">sys.</code><code class="descname">version</code><a class="headerlink" href="#sys.version" title="Permalink to this definition">¶</a></dt>
 
1266
<dd><p>A string containing the version number of the Python interpreter plus additional
 
1267
information on the build number and compiler used.  This string is displayed
 
1268
when the interactive interpreter is started.  Do not extract version information
 
1269
out of it, rather, use <a class="reference internal" href="#sys.version_info" title="sys.version_info"><code class="xref py py-data docutils literal"><span class="pre">version_info</span></code></a> and the functions provided by the
 
1270
<a class="reference internal" href="platform.html#module-platform" title="platform: Retrieves as much platform identifying data as possible."><code class="xref py py-mod docutils literal"><span class="pre">platform</span></code></a> module.</p>
 
1271
</dd></dl>
 
1272
 
 
1273
<dl class="data">
 
1274
<dt id="sys.api_version">
 
1275
<code class="descclassname">sys.</code><code class="descname">api_version</code><a class="headerlink" href="#sys.api_version" title="Permalink to this definition">¶</a></dt>
 
1276
<dd><p>The C API version for this interpreter.  Programmers may find this useful when
 
1277
debugging version conflicts between Python and extension modules.</p>
 
1278
<div class="versionadded">
 
1279
<p><span class="versionmodified">New in version 2.3.</span></p>
 
1280
</div>
 
1281
</dd></dl>
 
1282
 
 
1283
<dl class="data">
 
1284
<dt id="sys.version_info">
 
1285
<code class="descclassname">sys.</code><code class="descname">version_info</code><a class="headerlink" href="#sys.version_info" title="Permalink to this definition">¶</a></dt>
 
1286
<dd><p>A tuple containing the five components of the version number: <em>major</em>, <em>minor</em>,
 
1287
<em>micro</em>, <em>releaselevel</em>, and <em>serial</em>.  All values except <em>releaselevel</em> are
 
1288
integers; the release level is <code class="docutils literal"><span class="pre">'alpha'</span></code>, <code class="docutils literal"><span class="pre">'beta'</span></code>, <code class="docutils literal"><span class="pre">'candidate'</span></code>, or
 
1289
<code class="docutils literal"><span class="pre">'final'</span></code>.  The <code class="docutils literal"><span class="pre">version_info</span></code> value corresponding to the Python version 2.0
 
1290
is <code class="docutils literal"><span class="pre">(2,</span> <span class="pre">0,</span> <span class="pre">0,</span> <span class="pre">'final',</span> <span class="pre">0)</span></code>.  The components can also be accessed by name,
 
1291
so <code class="docutils literal"><span class="pre">sys.version_info[0]</span></code> is equivalent to <code class="docutils literal"><span class="pre">sys.version_info.major</span></code>
 
1292
and so on.</p>
 
1293
<div class="versionadded">
 
1294
<p><span class="versionmodified">New in version 2.0.</span></p>
 
1295
</div>
 
1296
<div class="versionchanged">
 
1297
<p><span class="versionmodified">Changed in version 2.7: </span>Added named component attributes</p>
 
1298
</div>
 
1299
</dd></dl>
 
1300
 
 
1301
<dl class="data">
 
1302
<dt id="sys.warnoptions">
 
1303
<code class="descclassname">sys.</code><code class="descname">warnoptions</code><a class="headerlink" href="#sys.warnoptions" title="Permalink to this definition">¶</a></dt>
 
1304
<dd><p>This is an implementation detail of the warnings framework; do not modify this
 
1305
value.  Refer to the <a class="reference internal" href="warnings.html#module-warnings" title="warnings: Issue warning messages and control their disposition."><code class="xref py py-mod docutils literal"><span class="pre">warnings</span></code></a> module for more information on the warnings
 
1306
framework.</p>
 
1307
</dd></dl>
 
1308
 
 
1309
<dl class="data">
 
1310
<dt id="sys.winver">
 
1311
<code class="descclassname">sys.</code><code class="descname">winver</code><a class="headerlink" href="#sys.winver" title="Permalink to this definition">¶</a></dt>
 
1312
<dd><p>The version number used to form registry keys on Windows platforms. This is
 
1313
stored as string resource 1000 in the Python DLL.  The value is normally the
 
1314
first three characters of <a class="reference internal" href="#sys.version" title="sys.version"><code class="xref py py-const docutils literal"><span class="pre">version</span></code></a>.  It is provided in the <a class="reference internal" href="#module-sys" title="sys: Access system-specific parameters and functions."><code class="xref py py-mod docutils literal"><span class="pre">sys</span></code></a>
 
1315
module for informational purposes; modifying this value has no effect on the
 
1316
registry keys used by Python. Availability: Windows.</p>
 
1317
</dd></dl>
 
1318
 
 
1319
<p class="rubric">Citations</p>
 
1320
<table class="docutils citation" frame="void" id="c99" rules="none">
 
1321
<colgroup><col class="label" /><col /></colgroup>
 
1322
<tbody valign="top">
 
1323
<tr><td class="label"><a class="fn-backref" href="#id1">[C99]</a></td><td>ISO/IEC 9899:1999.  &#8220;Programming languages &#8211; C.&#8221;  A public draft of this standard is available at <a class="reference external" href="http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1256.pdf">http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1256.pdf</a>.</td></tr>
 
1324
</tbody>
 
1325
</table>
 
1326
</div>
 
1327
 
 
1328
 
 
1329
          </div>
 
1330
        </div>
 
1331
      </div>
 
1332
      <div class="sphinxsidebar" role="navigation" aria-label="main navigation">
 
1333
        <div class="sphinxsidebarwrapper">
 
1334
  <h4>Previous topic</h4>
 
1335
  <p class="topless"><a href="python.html"
 
1336
                        title="previous chapter">28. Python Runtime Services</a></p>
 
1337
  <h4>Next topic</h4>
 
1338
  <p class="topless"><a href="sysconfig.html"
 
1339
                        title="next chapter">28.2. <code class="docutils literal"><span class="pre">sysconfig</span></code> &#8212; Provide access to Python&#8217;s configuration information</a></p>
 
1340
<h3>This Page</h3>
 
1341
<ul class="this-page-menu">
 
1342
  <li><a href="../bugs.html">Report a Bug</a></li>
 
1343
  <li><a href="../_sources/library/sys.txt"
 
1344
         rel="nofollow">Show Source</a></li>
 
1345
</ul>
 
1346
 
 
1347
<div id="searchbox" style="display: none" role="search">
 
1348
  <h3>Quick search</h3>
 
1349
    <form class="search" action="../search.html" method="get">
 
1350
      <input type="text" name="q" />
 
1351
      <input type="submit" value="Go" />
 
1352
      <input type="hidden" name="check_keywords" value="yes" />
 
1353
      <input type="hidden" name="area" value="default" />
 
1354
    </form>
 
1355
    <p class="searchtip" style="font-size: 90%">
 
1356
    Enter search terms or a module, class or function name.
 
1357
    </p>
 
1358
</div>
 
1359
<script type="text/javascript">$('#searchbox').show(0);</script>
 
1360
        </div>
 
1361
      </div>
 
1362
      <div class="clearer"></div>
 
1363
    </div>  
 
1364
    <div class="related" role="navigation" aria-label="related navigation">
 
1365
      <h3>Navigation</h3>
 
1366
      <ul>
 
1367
        <li class="right" style="margin-right: 10px">
 
1368
          <a href="../genindex.html" title="General Index"
 
1369
             >index</a></li>
 
1370
        <li class="right" >
 
1371
          <a href="../py-modindex.html" title="Python Module Index"
 
1372
             >modules</a> |</li>
 
1373
        <li class="right" >
 
1374
          <a href="sysconfig.html" title="28.2. sysconfig — Provide access to Python’s configuration information"
 
1375
             >next</a> |</li>
 
1376
        <li class="right" >
 
1377
          <a href="python.html" title="28. Python Runtime Services"
 
1378
             >previous</a> |</li>
 
1379
        <li><img src="../_static/py.png" alt=""
 
1380
                 style="vertical-align: middle; margin-top: -1px"/></li>
 
1381
        <li><a href="https://www.python.org/">Python</a> &raquo;</li>
 
1382
        <li>
 
1383
          <span class="version_switcher_placeholder">2.7.12</span>
 
1384
          <a href="../index.html">Documentation</a> &raquo;
 
1385
        </li>
 
1386
 
 
1387
          <li class="nav-item nav-item-1"><a href="index.html" >The Python Standard Library</a> &raquo;</li>
 
1388
          <li class="nav-item nav-item-2"><a href="python.html" >28. Python Runtime Services</a> &raquo;</li> 
 
1389
      </ul>
 
1390
    </div>  
 
1391
    <div class="footer">
 
1392
    &copy; <a href="../copyright.html">Copyright</a> 1990-2016, Python Software Foundation.
 
1393
    <br />
 
1394
    The Python Software Foundation is a non-profit corporation.
 
1395
    <a href="https://www.python.org/psf/donations/">Please donate.</a>
 
1396
    <br />
 
1397
    Last updated on Nov 26, 2016.
 
1398
    <a href="../bugs.html">Found a bug</a>?
 
1399
    <br />
 
1400
    Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.3.3.
 
1401
    </div>
 
1402
 
 
1403
  </body>
 
1404
</html>
 
 
b'\\ No newline at end of file'