📄 module-sys.html
字号:
<dt><b><a name='l2h-243'><tt>last_traceback</tt></a></b><dd>
These three variables are not always defined; they are set when an
exception is not handled and the interpreter prints an error message
and a stack traceback. Their intended use is to allow an interactive
user to import a debugger module and engage in post-mortem debugging
without having to re-execute the command that caused the error.
(Typical use is "<tt class="samp">import pdb; pdb.pm()</tt>" to enter the post-mortem
debugger; see the chapter ``The Python Debugger'' for more
information.)
<P>
The meaning of the variables is the same
as that of the return values from <tt class="function">exc_info()</tt> above.
(Since there is only one interactive thread, thread-safety is not a
concern for these variables, unlike for <code>exc_type</code> etc.)
</dl>
<P>
<dl><dt><b><a name='l2h-223'><tt>maxint</tt></a></b>
<dd>
The largest positive integer supported by Python's regular integer
type. This is at least 2**31-1. The largest negative integer is
<code>-maxint-1</code> - the asymmetry results from the use of 2's
complement binary arithmetic.
</dl>
<P>
<dl><dt><b><a name='l2h-224'><tt>modules</tt></a></b>
<dd>
This is a dictionary that maps module names to modules which have
already been loaded. This can be manipulated to force reloading of
modules and other tricks. Note that removing a module from this
dictionary is <i>not</i> the same as calling
<tt class="function">reload()</tt> on the corresponding module
object.
</dl>
<P>
<dl><dt><b><a name='l2h-225'><tt>path</tt></a></b>
<dd>
A list of strings that specifies the search path for modules.
Initialized from the environment variable <a class="envvar" name='l2h-247'>$PYTHONPATH</a>, or an
installation-dependent default.
<P>
The first item of this list, <code>path[0]</code>, is the
directory containing the script that was used to invoke the Python
interpreter. If the script directory is not available (e.g. if the
interpreter is invoked interactively or if the script is read from
standard input), <code>path[0]</code> is the empty string, which directs
Python to search modules in the current directory first. Notice that
the script directory is inserted <i>before</i> the entries inserted as
a result of <a class="envvar" name='l2h-248'>$PYTHONPATH</a>.
</dl>
<P>
<dl><dt><b><a name='l2h-226'><tt>platform</tt></a></b>
<dd>
This string contains a platform identifier, e.g. <code>'sunos5'</code> or
<code>'linux1'</code>. This can be used to append platform-specific
components to <code>path</code>, for instance.
</dl>
<P>
<dl><dt><b><a name='l2h-227'><tt>prefix</tt></a></b>
<dd>
A string giving the site-specific directory prefix where the platform
independent Python files are installed; by default, this is the string
<code>'/usr/local'</code>. This can be set at build time with the
<b class="programopt">--prefix</b> argument to the
<b class="program">configure</b> script. The main collection of Python library
modules is installed in the directory <code>prefix +
'/lib/python<var>version</var>'</code> while the platform independent header
files (all except <span class="file">config.h</span>) are stored in <code>prefix +
'/include/python<var>version</var>'</code>, where <var>version</var> is equal to
<code>version[:3]</code>.
</dl>
<P>
<dl><dt><b><a name='l2h-228'><tt>ps1</tt></a></b>
<dd>
<dt><b><a name='l2h-249'><tt>ps2</tt></a></b><dd>
Strings specifying the primary and secondary prompt of the
interpreter. These are only defined if the interpreter is in
interactive mode. Their initial values in this case are
<code>'»> '</code> and <code>'... '</code>. If a non-string object is assigned
to either variable, its <tt class="function">str()</tt> is re-evaluated each time
the interpreter prepares to read a new interactive command; this can
be used to implement a dynamic prompt.
</dl>
<P>
<dl><dt><b><a name='l2h-229'><tt class='function'>setcheckinterval</tt></a></b> (<var>interval</var>)
<dd>
Set the interpreter's ``check interval''. This integer value
determines how often the interpreter checks for periodic things such
as thread switches and signal handlers. The default is <code>10</code>, meaning
the check is performed every 10 Python virtual instructions. Setting
it to a larger value may increase performance for programs using
threads. Setting it to a value <code><=</code> 0 checks every virtual instruction,
maximizing responsiveness as well as overhead.
</dl>
<P>
<dl><dt><b><a name='l2h-230'><tt class='function'>setprofile</tt></a></b> (<var>profilefunc</var>)
<dd>
Set the system's profile function, which allows you to implement a
Python source code profiler in Python. See the chapter on the
Python Profiler. The system's profile function
is called similarly to the system's trace function (see
<tt class="function">settrace()</tt>), but it isn't called for each executed line of
code (only on call and return and when an exception occurs). Also,
its return value is not used, so it can just return <code>None</code>.
</dl>
<P>
<dl><dt><b><a name='l2h-231'><tt class='function'>setrecursionlimit</tt></a></b> (<var>limit</var>)
<dd>
Set the maximum depth of the Python interpreter stack to <var>limit</var>.
This limit prevents infinite recursion from causing an overflow of the
C stack and crashing Python.
<P>
The highest possible limit is platform-dependent. A user may need to
set the limit higher when she has a program that requires deep
recursion and a platform that supports a higher limit. This should be
done with care, because a too-high limit can lead to a crash.
</dl>
<P>
<dl><dt><b><a name='l2h-232'><tt class='function'>settrace</tt></a></b> (<var>tracefunc</var>)
<dd>
Set the system's trace function, which allows you to implement a
Python source code debugger in Python. See section ``How It Works''
in the chapter on the Python Debugger.
</dl>
<P>
<dl><dt><b><a name='l2h-233'><tt>stdin</tt></a></b>
<dd>
<dt><b><a name='l2h-253'><tt>stdout</tt></a></b><dd>
<dt><b><a name='l2h-254'><tt>stderr</tt></a></b><dd>
File objects corresponding to the interpreter's standard input,
output and error streams. <code>stdin</code> is used for all
interpreter input except for scripts but including calls to
<tt class="function">input()</tt> and
<tt class="function">raw_input()</tt>. <code>stdout</code> is used
for the output of <tt class="keyword">print</tt> and expression statements and for the
prompts of <tt class="function">input()</tt> and <tt class="function">raw_input()</tt>. The interpreter's
own prompts and (almost all of) its error messages go to
<code>stderr</code>. <code>stdout</code> and <code>stderr</code> needn't
be built-in file objects: any object is acceptable as long as it has
a <tt class="method">write()</tt> method that takes a string argument. (Changing these
objects doesn't affect the standard I/O streams of processes
executed by <tt class="function">os.popen()</tt>, <tt class="function">os.system()</tt> or the
<tt class="function">exec*()</tt> family of functions in the <tt class='module'><a href="module-os.html" tppabs="http://www.python.org/doc/current/lib/module-os.html">os</a></tt> module.)
</dl>
<P>
<dl><dt><b><a name='l2h-234'><tt>__stdin__</tt></a></b>
<dd>
<dt><b><a name='l2h-258'><tt>__stdout__</tt></a></b><dd>
<dt><b><a name='l2h-259'><tt>__stderr__</tt></a></b><dd>
These objects contain the original values of <code>stdin</code>,
<code>stderr</code> and <code>stdout</code> at the start of the program. They are
used during finalization, and could be useful to restore the actual
files to known working file objects in case they have been overwritten
with a broken object.
</dl>
<P>
<dl><dt><b><a name='l2h-235'><tt>tracebacklimit</tt></a></b>
<dd>
When this variable is set to an integer value, it determines the
maximum number of levels of traceback information printed when an
unhandled exception occurs. The default is <code>1000</code>. When set to
0 or less, all traceback information is suppressed and only the
exception type and value are printed.
</dl>
<P>
<dl><dt><b><a name='l2h-236'><tt>version</tt></a></b>
<dd>
A string containing the version number of the Python interpreter plus
additional information on the build number and compiler used. It has
a value of the form <code>'<var>version</var> (#<var>build_number</var>,
<var>build_date</var>, <var>build_time</var>) [<var>compiler</var>]'</code>. The first
three characters are used to identify the version in the installation
directories (where appropriate on each platform). An example:
<P>
<dl><dd><pre class="verbatim">
>>> import sys
>>> sys.version
'1.5.2 (#0 Apr 13 1999, 10:51:12) [MSC 32 bit (Intel)]'
</pre></dl>
</dl>
<P>
<dl><dt><b><a name='l2h-237'><tt>version_info</tt></a></b>
<dd>
A tuple containing the five components of the version number:
<var>major</var>, <var>minor</var>, <var>micro</var>, <var>releaselevel</var>, and
<var>serial</var>. All values except <var>releaselevel</var> are integers; the
release level is <code>'alpha'</code>, <code>'beta'</code>,
<code>'candidate'</code>, or <code>'final'</code>. The <code>version_info</code> value
corresponding to the Python version 2.0 is
<code>(2, 0, 0, 'final', 0)</code>.
New in version 2.0.
</dl>
<P>
<dl><dt><b><a name='l2h-238'><tt>winver</tt></a></b>
<dd>
The version number used to form registry keys on Windows platforms.
This is stored as string resource 1000 in the Python DLL. The value
is normally the first three characters of <tt class="constant">version</tt>. It is
provided in the <tt class="module">sys</tt> module for informational purposes;
modifying this value has no effect on the registry keys used by
Python.
Availability: Windows.
</dl>
<DIV CLASS="navigation"><p><hr><table align="center" width="100%" cellpadding="0" cellspacing="2">
<tr>
<td><A href="python.html" tppabs="http://www.python.org/doc/current/lib/python.html"><img src="previous.gif" tppabs="http://www.python.org/doc/current/icons/previous.gif" border="0" height="32"
alt="Previous Page" width="32"></A></td>
<td><A href="python.html" tppabs="http://www.python.org/doc/current/lib/python.html"><img src="up.gif" tppabs="http://www.python.org/doc/current/icons/up.gif" border="0" height="32"
alt="Up One Level" width="32"></A></td>
<td><A href="module-gc.html" tppabs="http://www.python.org/doc/current/lib/module-gc.html"><img src="next.gif" tppabs="http://www.python.org/doc/current/icons/next.gif" border="0" height="32"
alt="Next Page" width="32"></A></td>
<td align="center" width="100%">Python Library Reference</td>
<td><A href="contents.html" tppabs="http://www.python.org/doc/current/lib/contents.html"><img src="contents.gif" tppabs="http://www.python.org/doc/current/icons/contents.gif" border="0" height="32"
alt="Contents" width="32"></A></td>
<td><a href="modindex.html" tppabs="http://www.python.org/doc/current/lib/modindex.html" title="Module Index"><img src="modules.gif" tppabs="http://www.python.org/doc/current/icons/modules.gif" border="0" height="32"
alt="Module Index" width="32"></a></td>
<td><A href="genindex.html" tppabs="http://www.python.org/doc/current/lib/genindex.html"><img src="index.gif" tppabs="http://www.python.org/doc/current/icons/index.gif" border="0" height="32"
alt="Index" width="32"></A></td>
</tr></table>
<b class="navlabel">Previous:</b> <a class="sectref" href="python.html" tppabs="http://www.python.org/doc/current/lib/python.html">3. Python Runtime Services</A>
<b class="navlabel">Up:</b> <a class="sectref" href="python.html" tppabs="http://www.python.org/doc/current/lib/python.html">3. Python Runtime Services</A>
<b class="navlabel">Next:</b> <a class="sectref" href="module-gc.html" tppabs="http://www.python.org/doc/current/lib/module-gc.html">3.2 gc </A>
</DIV>
<!--End of Navigation Panel-->
<ADDRESS>
<hr>See <i><a href="about.html" tppabs="http://www.python.org/doc/current/lib/about.html">About this document...</a></i> for information on suggesting changes.
</ADDRESS>
</BODY>
</HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -