blob: 4ab32472be10b7a66ed46183dadb00556fbe156e [file] [log] [blame]
Fred Drake295da241998-08-10 19:42:37 +00001\section{\module{sys} ---
Fred Drakeffbe6871999-04-22 21:23:22 +00002 System-specific parameters and functions}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +00003
Fred Drakeffbe6871999-04-22 21:23:22 +00004\declaremodule{builtin}{sys}
Fred Drake295da241998-08-10 19:42:37 +00005\modulesynopsis{Access system-specific parameters and functions.}
Fred Drakeb91e9341998-07-23 17:59:49 +00006
Guido van Rossum5fdeeea1994-01-02 01:22:07 +00007This module provides access to some variables used or maintained by the
8interpreter and to functions that interact strongly with the interpreter.
9It is always available.
10
Guido van Rossum470be141995-03-17 16:07:09 +000011
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000012\begin{datadesc}{argv}
13 The list of command line arguments passed to a Python script.
Fred Drake72182022001-07-18 17:52:58 +000014 \code{argv[0]} is the script name (it is operating system dependent
15 whether this is a full pathname or not). If the command was
16 executed using the \programopt{-c} command line option to the
17 interpreter, \code{argv[0]} is set to the string \code{'-c'}. If no
Guido van Rossumd8faa362007-04-27 19:54:29 +000018 script name was passed to the Python interpreter, \code{argv[0]} is
19 the empty string.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000020\end{datadesc}
21
Fred Drakea2b6ad62000-08-15 04:24:43 +000022\begin{datadesc}{byteorder}
Fred Drake68e29152000-08-14 15:47:30 +000023 An indicator of the native byte order. This will have the value
Thomas Wouters0e3f5912006-08-11 14:57:12 +000024 \code{'big'} on big-endian (most-significant byte first) platforms,
Fred Drake68e29152000-08-14 15:47:30 +000025 and \code{'little'} on little-endian (least-significant byte first)
26 platforms.
27 \versionadded{2.0}
28\end{datadesc}
29
Martin v. Löwis43b57802006-01-05 23:38:54 +000030\begin{datadesc}{subversion}
31 A triple (repo, branch, version) representing the Subversion
32 information of the Python interpreter.
33 \var{repo} is the name of the repository, \code{'CPython'}.
Georg Brandl74ef6942006-01-06 19:26:42 +000034 \var{branch} is a string of one of the forms \code{'trunk'},
Martin v. Löwis43b57802006-01-05 23:38:54 +000035 \code{'branches/name'} or \code{'tags/name'}.
36 \var{version} is the output of \code{svnversion}, if the
37 interpreter was built from a Subversion checkout; it contains
38 the revision number (range) and possibly a trailing 'M' if
39 there were local modifications. If the tree was exported
40 (or svnversion was not available), it is the revision of
41 \code{Include/patchlevel.h} if the branch is a tag. Otherwise,
42 it is \code{None}.
Neal Norwitzb04747f2005-12-18 01:36:44 +000043 \versionadded{2.5}
Thomas Wouters0e3f5912006-08-11 14:57:12 +000044\end{datadesc}
Barry Warsaw2a38a862005-12-18 01:27:35 +000045
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000046\begin{datadesc}{builtin_module_names}
Guido van Rossum0d2971b1997-01-06 23:01:02 +000047 A tuple of strings giving the names of all modules that are compiled
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000048 into this Python interpreter. (This information is not available in
Fred Drake0fd72ee1998-03-08 05:43:51 +000049 any other way --- \code{modules.keys()} only lists the imported
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000050 modules.)
51\end{datadesc}
52
Guido van Rossum3e5fe421998-06-10 17:57:44 +000053\begin{datadesc}{copyright}
Fred Drake72182022001-07-18 17:52:58 +000054 A string containing the copyright pertaining to the Python
55 interpreter.
Guido van Rossum3e5fe421998-06-10 17:57:44 +000056\end{datadesc}
57
Thomas Wouters0e3f5912006-08-11 14:57:12 +000058\begin{funcdesc}{_current_frames}{}
59 Return a dictionary mapping each thread's identifier to the topmost stack
60 frame currently active in that thread at the time the function is called.
61 Note that functions in the \refmodule{traceback} module can build the
62 call stack given such a frame.
63
64 This is most useful for debugging deadlock: this function does not
65 require the deadlocked threads' cooperation, and such threads' call stacks
66 are frozen for as long as they remain deadlocked. The frame returned
67 for a non-deadlocked thread may bear no relationship to that thread's
68 current activity by the time calling code examines the frame.
69
70 This function should be used for internal and specialized purposes
71 only.
72 \versionadded{2.5}
73\end{funcdesc}
74
Fred Drake38e5d272000-04-03 20:13:55 +000075\begin{datadesc}{dllhandle}
Fred Drake72182022001-07-18 17:52:58 +000076 Integer specifying the handle of the Python DLL.
77 Availability: Windows.
Fred Drake38e5d272000-04-03 20:13:55 +000078\end{datadesc}
79
Moshe Zadkaf68f2fe2001-01-11 05:41:27 +000080\begin{funcdesc}{displayhook}{\var{value}}
Fred Drake72182022001-07-18 17:52:58 +000081 If \var{value} is not \code{None}, this function prints it to
82 \code{sys.stdout}, and saves it in \code{__builtin__._}.
Moshe Zadkaf68f2fe2001-01-11 05:41:27 +000083
Fred Drake72182022001-07-18 17:52:58 +000084 \code{sys.displayhook} is called on the result of evaluating an
85 expression entered in an interactive Python session. The display of
86 these values can be customized by assigning another one-argument
87 function to \code{sys.displayhook}.
Moshe Zadkaf68f2fe2001-01-11 05:41:27 +000088\end{funcdesc}
89
Ka-Ping Yeeb5c51322001-03-23 02:46:52 +000090\begin{funcdesc}{excepthook}{\var{type}, \var{value}, \var{traceback}}
Fred Drake72182022001-07-18 17:52:58 +000091 This function prints out a given traceback and exception to
92 \code{sys.stderr}.
Ka-Ping Yeeb5c51322001-03-23 02:46:52 +000093
Fred Drake72182022001-07-18 17:52:58 +000094 When an exception is raised and uncaught, the interpreter calls
95 \code{sys.excepthook} with three arguments, the exception class,
96 exception instance, and a traceback object. In an interactive
97 session this happens just before control is returned to the prompt;
98 in a Python program this happens just before the program exits. The
99 handling of such top-level exceptions can be customized by assigning
100 another three-argument function to \code{sys.excepthook}.
Ka-Ping Yeeb5c51322001-03-23 02:46:52 +0000101\end{funcdesc}
102
103\begin{datadesc}{__displayhook__}
104\dataline{__excepthook__}
Fred Drake72182022001-07-18 17:52:58 +0000105 These objects contain the original values of \code{displayhook} and
106 \code{excepthook} at the start of the program. They are saved so
107 that \code{displayhook} and \code{excepthook} can be restored in
108 case they happen to get replaced with broken objects.
Ka-Ping Yeeb5c51322001-03-23 02:46:52 +0000109\end{datadesc}
110
Guido van Rossum871cf161997-10-20 22:38:43 +0000111\begin{funcdesc}{exc_info}{}
Fred Drake72182022001-07-18 17:52:58 +0000112 This function returns a tuple of three values that give information
113 about the exception that is currently being handled. The
114 information returned is specific both to the current thread and to
115 the current stack frame. If the current stack frame is not handling
116 an exception, the information is taken from the calling stack frame,
117 or its caller, and so on until a stack frame is found that is
118 handling an exception. Here, ``handling an exception'' is defined
119 as ``executing or having executed an except clause.'' For any stack
120 frame, only information about the most recently handled exception is
121 accessible.
Guido van Rossum871cf161997-10-20 22:38:43 +0000122
Fred Drake72182022001-07-18 17:52:58 +0000123 If no exception is being handled anywhere on the stack, a tuple
124 containing three \code{None} values is returned. Otherwise, the
125 values returned are \code{(\var{type}, \var{value},
126 \var{traceback})}. Their meaning is: \var{type} gets the exception
Neal Norwitz847207a2003-05-29 02:17:23 +0000127 type of the exception being handled (a class object);
Fred Drake72182022001-07-18 17:52:58 +0000128 \var{value} gets the exception parameter (its \dfn{associated value}
129 or the second argument to \keyword{raise}, which is always a class
130 instance if the exception type is a class object); \var{traceback}
131 gets a traceback object (see the Reference Manual) which
132 encapsulates the call stack at the point where the exception
133 originally occurred. \obindex{traceback}
Guido van Rossum871cf161997-10-20 22:38:43 +0000134
Fred Drake0aa811c2001-10-20 04:24:09 +0000135 \warning{Assigning the \var{traceback} return value to a
Fred Drake72182022001-07-18 17:52:58 +0000136 local variable in a function that is handling an exception will
137 cause a circular reference. This will prevent anything referenced
138 by a local variable in the same function or by the traceback from
139 being garbage collected. Since most functions don't need access to
140 the traceback, the best solution is to use something like
Fred Drake7731ed42002-01-05 04:00:03 +0000141 \code{exctype, value = sys.exc_info()[:2]} to extract only the
Fred Drake72182022001-07-18 17:52:58 +0000142 exception type and value. If you do need the traceback, make sure
143 to delete it after use (best done with a \keyword{try}
144 ... \keyword{finally} statement) or to call \function{exc_info()} in
Tim Peters98791af2001-10-23 01:59:54 +0000145 a function that does not itself handle an exception.} \note{Beginning
146 with Python 2.2, such cycles are automatically reclaimed when garbage
147 collection is enabled and they become unreachable, but it remains more
148 efficient to avoid creating cycles.}
Guido van Rossum871cf161997-10-20 22:38:43 +0000149\end{funcdesc}
150
Guido van Rossum0a3c7531997-06-02 17:32:41 +0000151\begin{datadesc}{exec_prefix}
Fred Drake72182022001-07-18 17:52:58 +0000152 A string giving the site-specific directory prefix where the
153 platform-dependent Python files are installed; by default, this is
154 also \code{'/usr/local'}. This can be set at build time with the
155 \longprogramopt{exec-prefix} argument to the \program{configure}
156 script. Specifically, all configuration files (e.g. the
Martin v. Löwis4f1cd8b2001-07-26 13:41:06 +0000157 \file{pyconfig.h} header file) are installed in the directory
Fred Drake72182022001-07-18 17:52:58 +0000158 \code{exec_prefix + '/lib/python\var{version}/config'}, and shared
159 library modules are installed in \code{exec_prefix +
160 '/lib/python\var{version}/lib-dynload'}, where \var{version} is
161 equal to \code{version[:3]}.
Guido van Rossum0a3c7531997-06-02 17:32:41 +0000162\end{datadesc}
163
Guido van Rossum3e5fe421998-06-10 17:57:44 +0000164\begin{datadesc}{executable}
Fred Drake72182022001-07-18 17:52:58 +0000165 A string giving the name of the executable binary for the Python
166 interpreter, on systems where this makes sense.
Guido van Rossum3e5fe421998-06-10 17:57:44 +0000167\end{datadesc}
168
Guido van Rossum04307ce1998-11-23 17:49:53 +0000169\begin{funcdesc}{exit}{\optional{arg}}
Fred Drake72182022001-07-18 17:52:58 +0000170 Exit from Python. This is implemented by raising the
171 \exception{SystemExit} exception, so cleanup actions specified by
172 finally clauses of \keyword{try} statements are honored, and it is
173 possible to intercept the exit attempt at an outer level. The
174 optional argument \var{arg} can be an integer giving the exit status
175 (defaulting to zero), or another type of object. If it is an
176 integer, zero is considered ``successful termination'' and any
177 nonzero value is considered ``abnormal termination'' by shells and
178 the like. Most systems require it to be in the range 0-127, and
179 produce undefined results otherwise. Some systems have a convention
180 for assigning specific meanings to specific exit codes, but these
Fred Drakec37b65e2001-11-28 07:26:15 +0000181 are generally underdeveloped; \UNIX{} programs generally use 2 for
Fred Drake72182022001-07-18 17:52:58 +0000182 command line syntax errors and 1 for all other kind of errors. If
183 another type of object is passed, \code{None} is equivalent to
184 passing zero, and any other object is printed to \code{sys.stderr}
185 and results in an exit code of 1. In particular,
186 \code{sys.exit("some error message")} is a quick way to exit a
187 program when an error occurs.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000188\end{funcdesc}
189
Tim Peterse5e065b2003-07-06 18:36:54 +0000190\begin{funcdesc}{getcheckinterval}{}
191 Return the interpreter's ``check interval'';
192 see \function{setcheckinterval()}.
Neal Norwitz7cb229d2003-07-07 14:11:53 +0000193 \versionadded{2.3}
Tim Peterse5e065b2003-07-06 18:36:54 +0000194\end{funcdesc}
195
Fred Drake8940faf2000-10-25 21:02:55 +0000196\begin{funcdesc}{getdefaultencoding}{}
197 Return the name of the current default string encoding used by the
198 Unicode implementation.
199 \versionadded{2.0}
200\end{funcdesc}
201
Martin v. Löwisf0473d52001-07-18 16:17:16 +0000202\begin{funcdesc}{getdlopenflags}{}
Fred Drake5d808fb2001-07-18 16:35:05 +0000203 Return the current value of the flags that are used for
204 \cfunction{dlopen()} calls. The flag constants are defined in the
205 \refmodule{dl} and \module{DLFCN} modules.
206 Availability: \UNIX.
207 \versionadded{2.2}
Martin v. Löwisf0473d52001-07-18 16:17:16 +0000208\end{funcdesc}
209
Martin v. Löwis73d538b2003-03-05 15:13:47 +0000210\begin{funcdesc}{getfilesystemencoding}{}
211 Return the name of the encoding used to convert Unicode filenames
212 into system file names, or \code{None} if the system default encoding
213 is used. The result value depends on the operating system:
214\begin{itemize}
215\item On Windows 9x, the encoding is ``mbcs''.
216\item On Mac OS X, the encoding is ``utf-8''.
Thomas Wouters0e3f5912006-08-11 14:57:12 +0000217\item On \UNIX, the encoding is the user's preference
218 according to the result of nl_langinfo(CODESET), or \constant{None}
219 if the \code{nl_langinfo(CODESET)} failed.
Martin v. Löwis73d538b2003-03-05 15:13:47 +0000220\item On Windows NT+, file names are Unicode natively, so no conversion
Thomas Wouters0e3f5912006-08-11 14:57:12 +0000221 is performed. \function{getfilesystemencoding()} still returns
222 \code{'mbcs'}, as this is the encoding that applications should use
223 when they explicitly want to convert Unicode strings to byte strings
224 that are equivalent when used as file names.
Martin v. Löwis73d538b2003-03-05 15:13:47 +0000225\end{itemize}
226 \versionadded{2.3}
227\end{funcdesc}
228
Guido van Rossum6e91c6a1998-02-07 21:17:05 +0000229\begin{funcdesc}{getrefcount}{object}
Fred Drake72182022001-07-18 17:52:58 +0000230 Return the reference count of the \var{object}. The count returned
231 is generally one higher than you might expect, because it includes
232 the (temporary) reference as an argument to
233 \function{getrefcount()}.
Guido van Rossum6e91c6a1998-02-07 21:17:05 +0000234\end{funcdesc}
235
Jeremy Hyltonee5adfb2000-08-31 19:23:01 +0000236\begin{funcdesc}{getrecursionlimit}{}
Fred Drake72182022001-07-18 17:52:58 +0000237 Return the current value of the recursion limit, the maximum depth
238 of the Python interpreter stack. This limit prevents infinite
239 recursion from causing an overflow of the C stack and crashing
240 Python. It can be set by \function{setrecursionlimit()}.
Jeremy Hyltonee5adfb2000-08-31 19:23:01 +0000241\end{funcdesc}
242
Barry Warsawb6a54d22000-12-06 21:47:46 +0000243\begin{funcdesc}{_getframe}{\optional{depth}}
Fred Drake72182022001-07-18 17:52:58 +0000244 Return a frame object from the call stack. If optional integer
245 \var{depth} is given, return the frame object that many calls below
246 the top of the stack. If that is deeper than the call stack,
247 \exception{ValueError} is raised. The default for \var{depth} is
248 zero, returning the frame at the top of the call stack.
Barry Warsawb6a54d22000-12-06 21:47:46 +0000249
Fred Drake72182022001-07-18 17:52:58 +0000250 This function should be used for internal and specialized purposes
251 only.
Barry Warsawb6a54d22000-12-06 21:47:46 +0000252\end{funcdesc}
253
Mark Hammond8696ebc2002-10-08 02:44:31 +0000254\begin{funcdesc}{getwindowsversion}{}
Thomas Wouters0e3f5912006-08-11 14:57:12 +0000255 Return a tuple containing five components, describing the Windows
256 version currently running. The elements are \var{major}, \var{minor},
Mark Hammond8696ebc2002-10-08 02:44:31 +0000257 \var{build}, \var{platform}, and \var{text}. \var{text} contains
258 a string while all other values are integers.
259
260 \var{platform} may be one of the following values:
Fred Drake8efc80a2004-11-11 04:39:56 +0000261
262 \begin{tableii}{l|l}{constant}{Constant}{Platform}
Georg Brandl71322122006-02-20 12:15:23 +0000263 \lineii{0 (VER_PLATFORM_WIN32s)} {Win32s on Windows 3.1}
264 \lineii{1 (VER_PLATFORM_WIN32_WINDOWS)}{Windows 95/98/ME}
265 \lineii{2 (VER_PLATFORM_WIN32_NT)} {Windows NT/2000/XP}
266 \lineii{3 (VER_PLATFORM_WIN32_CE)} {Windows CE}
Fred Drake8efc80a2004-11-11 04:39:56 +0000267 \end{tableii}
268
269 This function wraps the Win32 \cfunction{GetVersionEx()} function;
270 see the Microsoft documentation for more information about these
Mark Hammond8696ebc2002-10-08 02:44:31 +0000271 fields.
272
273 Availability: Windows.
274 \versionadded{2.3}
275\end{funcdesc}
276
Fred Drake4d65d732000-04-13 16:54:17 +0000277\begin{datadesc}{hexversion}
Fred Drake72182022001-07-18 17:52:58 +0000278 The version number encoded as a single integer. This is guaranteed
279 to increase with each version, including proper support for
280 non-production releases. For example, to test that the Python
281 interpreter is at least version 1.5.2, use:
Fred Drake4d65d732000-04-13 16:54:17 +0000282
283\begin{verbatim}
284if sys.hexversion >= 0x010502F0:
285 # use some advanced feature
286 ...
287else:
288 # use an alternative implementation or warn the user
289 ...
290\end{verbatim}
291
Fred Drake72182022001-07-18 17:52:58 +0000292 This is called \samp{hexversion} since it only really looks
293 meaningful when viewed as the result of passing it to the built-in
294 \function{hex()} function. The \code{version_info} value may be
295 used for a more human-friendly encoding of the same information.
296 \versionadded{1.5.2}
Fred Drake4d65d732000-04-13 16:54:17 +0000297\end{datadesc}
298
Georg Brandl66a796e2006-12-19 20:50:34 +0000299\begin{funcdesc}{intern}{string}
300 Enter \var{string} in the table of ``interned'' strings and return
301 the interned string -- which is \var{string} itself or a copy.
302 Interning strings is useful to gain a little performance on
303 dictionary lookup -- if the keys in a dictionary are interned, and
304 the lookup key is interned, the key comparisons (after hashing) can
305 be done by a pointer compare instead of a string compare. Normally,
306 the names used in Python programs are automatically interned, and
307 the dictionaries used to hold module, class or instance attributes
308 have interned keys. \versionchanged[Interned strings are not
309 immortal (like they used to be in Python 2.2 and before);
310 you must keep a reference to the return value of \function{intern()}
311 around to benefit from it]{2.3}
312\end{funcdesc}
313
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000314\begin{datadesc}{last_type}
315\dataline{last_value}
316\dataline{last_traceback}
Fred Drake72182022001-07-18 17:52:58 +0000317 These three variables are not always defined; they are set when an
318 exception is not handled and the interpreter prints an error message
319 and a stack traceback. Their intended use is to allow an
320 interactive user to import a debugger module and engage in
321 post-mortem debugging without having to re-execute the command that
322 caused the error. (Typical use is \samp{import pdb; pdb.pm()} to
Fred Drake8efc80a2004-11-11 04:39:56 +0000323 enter the post-mortem debugger; see chapter~\ref{debugger}, ``The
Fred Drake72182022001-07-18 17:52:58 +0000324 Python Debugger,'' for more information.)
Guido van Rossum871cf161997-10-20 22:38:43 +0000325
Fred Drake72182022001-07-18 17:52:58 +0000326 The meaning of the variables is the same as that of the return
327 values from \function{exc_info()} above. (Since there is only one
328 interactive thread, thread-safety is not a concern for these
329 variables, unlike for \code{exc_type} etc.)
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000330\end{datadesc}
331
Guido van Rossum3e5fe421998-06-10 17:57:44 +0000332\begin{datadesc}{maxint}
Fred Drake72182022001-07-18 17:52:58 +0000333 The largest positive integer supported by Python's regular integer
334 type. This is at least 2**31-1. The largest negative integer is
Fred Drakec05fc7d2001-09-04 18:18:36 +0000335 \code{-maxint-1} --- the asymmetry results from the use of 2's
Fred Drake72182022001-07-18 17:52:58 +0000336 complement binary arithmetic.
Guido van Rossum3e5fe421998-06-10 17:57:44 +0000337\end{datadesc}
338
Fred Drakec05fc7d2001-09-04 18:18:36 +0000339\begin{datadesc}{maxunicode}
340 An integer giving the largest supported code point for a Unicode
341 character. The value of this depends on the configuration option
342 that specifies whether Unicode characters are stored as UCS-2 or
343 UCS-4.
344\end{datadesc}
345
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000346\begin{datadesc}{modules}
Fred Drake0fd72ee1998-03-08 05:43:51 +0000347 This is a dictionary that maps module names to modules which have
348 already been loaded. This can be manipulated to force reloading of
Guido van Rossume7ba4952007-06-06 23:52:48 +0000349 modules and other tricks.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000350\end{datadesc}
351
352\begin{datadesc}{path}
Fred Drake2b67bee1998-01-13 18:35:51 +0000353\indexiii{module}{search}{path}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000354 A list of strings that specifies the search path for modules.
Guido van Rossum54ed2d32002-07-15 16:08:10 +0000355 Initialized from the environment variable \envvar{PYTHONPATH}, plus an
Fred Drake72182022001-07-18 17:52:58 +0000356 installation-dependent default.
Guido van Rossum0a3c7531997-06-02 17:32:41 +0000357
Guido van Rossum54ed2d32002-07-15 16:08:10 +0000358 As initialized upon program startup,
359 the first item of this list, \code{path[0]}, is the directory
Fred Drake72182022001-07-18 17:52:58 +0000360 containing the script that was used to invoke the Python
361 interpreter. If the script directory is not available (e.g. if the
362 interpreter is invoked interactively or if the script is read from
363 standard input), \code{path[0]} is the empty string, which directs
364 Python to search modules in the current directory first. Notice
365 that the script directory is inserted \emph{before} the entries
366 inserted as a result of \envvar{PYTHONPATH}.
Guido van Rossum54ed2d32002-07-15 16:08:10 +0000367
368 A program is free to modify this list for its own purposes.
Fred Drake38d7c1b2003-07-17 04:22:44 +0000369
Brett Cannon8b6cc2e2004-03-21 14:10:18 +0000370 \versionchanged[Unicode strings are no longer ignored]{2.3}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000371\end{datadesc}
372
Guido van Rossum6b686e91995-07-07 23:00:35 +0000373\begin{datadesc}{platform}
Fred Drake72182022001-07-18 17:52:58 +0000374 This string contains a platform identifier, e.g. \code{'sunos5'} or
375 \code{'linux1'}. This can be used to append platform-specific
376 components to \code{path}, for instance.
Guido van Rossum0a3c7531997-06-02 17:32:41 +0000377\end{datadesc}
378
379\begin{datadesc}{prefix}
Fred Drake72182022001-07-18 17:52:58 +0000380 A string giving the site-specific directory prefix where the
381 platform independent Python files are installed; by default, this is
382 the string \code{'/usr/local'}. This can be set at build time with
383 the \longprogramopt{prefix} argument to the \program{configure}
384 script. The main collection of Python library modules is installed
385 in the directory \code{prefix + '/lib/python\var{version}'} while
Martin v. Löwis4f1cd8b2001-07-26 13:41:06 +0000386 the platform independent header files (all except \file{pyconfig.h})
Fred Drake72182022001-07-18 17:52:58 +0000387 are stored in \code{prefix + '/include/python\var{version}'}, where
388 \var{version} is equal to \code{version[:3]}.
Guido van Rossum6b686e91995-07-07 23:00:35 +0000389\end{datadesc}
390
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000391\begin{datadesc}{ps1}
392\dataline{ps2}
Fred Drakee6cedb31998-04-03 07:05:16 +0000393\index{interpreter prompts}
394\index{prompts, interpreter}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000395 Strings specifying the primary and secondary prompt of the
396 interpreter. These are only defined if the interpreter is in
397 interactive mode. Their initial values in this case are
Thomas Wouters477c8d52006-05-27 19:21:47 +0000398 \code{'>>>~'} and \code{'...~'}. If a non-string object is
Fred Drake72182022001-07-18 17:52:58 +0000399 assigned to either variable, its \function{str()} is re-evaluated
400 each time the interpreter prepares to read a new interactive
401 command; this can be used to implement a dynamic prompt.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000402\end{datadesc}
403
Guido van Rossum9c51e411995-01-10 10:50:58 +0000404\begin{funcdesc}{setcheckinterval}{interval}
Fred Drake72182022001-07-18 17:52:58 +0000405 Set the interpreter's ``check interval''. This integer value
406 determines how often the interpreter checks for periodic things such
Skip Montanaroeec26f92003-07-02 21:38:34 +0000407 as thread switches and signal handlers. The default is \code{100},
408 meaning the check is performed every 100 Python virtual instructions.
Fred Drake72182022001-07-18 17:52:58 +0000409 Setting it to a larger value may increase performance for programs
410 using threads. Setting it to a value \code{<=} 0 checks every
411 virtual instruction, maximizing responsiveness as well as overhead.
Guido van Rossum7f49b7a1995-01-12 12:38:46 +0000412\end{funcdesc}
Guido van Rossum9c51e411995-01-10 10:50:58 +0000413
Fred Drake8940faf2000-10-25 21:02:55 +0000414\begin{funcdesc}{setdefaultencoding}{name}
415 Set the current default string encoding used by the Unicode
416 implementation. If \var{name} does not match any available
417 encoding, \exception{LookupError} is raised. This function is only
418 intended to be used by the \refmodule{site} module implementation
419 and, where needed, by \module{sitecustomize}. Once used by the
420 \refmodule{site} module, it is removed from the \module{sys}
421 module's namespace.
422% Note that \refmodule{site} is not imported if
423% the \programopt{-S} option is passed to the interpreter, in which
424% case this function will remain available.
425 \versionadded{2.0}
426\end{funcdesc}
427
Andrew M. Kuchling28bafb82001-07-19 01:17:15 +0000428\begin{funcdesc}{setdlopenflags}{n}
Fred Drake5d808fb2001-07-18 16:35:05 +0000429 Set the flags used by the interpreter for \cfunction{dlopen()}
430 calls, such as when the interpreter loads extension modules. Among
431 other things, this will enable a lazy resolving of symbols when
Andrew M. Kuchling28bafb82001-07-19 01:17:15 +0000432 importing a module, if called as \code{sys.setdlopenflags(0)}. To
433 share symbols across extension modules, call as
Fred Drake72182022001-07-18 17:52:58 +0000434 \code{sys.setdlopenflags(dl.RTLD_NOW | dl.RTLD_GLOBAL)}. Symbolic
Fred Drake5d808fb2001-07-18 16:35:05 +0000435 names for the flag modules can be either found in the \refmodule{dl}
436 module, or in the \module{DLFCN} module. If \module{DLFCN} is not
Fred Drake72182022001-07-18 17:52:58 +0000437 available, it can be generated from \file{/usr/include/dlfcn.h}
438 using the \program{h2py} script.
Fred Drake5d808fb2001-07-18 16:35:05 +0000439 Availability: \UNIX.
440 \versionadded{2.2}
Martin v. Löwisf0473d52001-07-18 16:17:16 +0000441\end{funcdesc}
442
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000443\begin{funcdesc}{setprofile}{profilefunc}
Fred Drake72182022001-07-18 17:52:58 +0000444 Set the system's profile function,\index{profile function} which
445 allows you to implement a Python source code profiler in
Fred Drake8efc80a2004-11-11 04:39:56 +0000446 Python.\index{profiler} See chapter~\ref{profile} for more
Fred Drake72182022001-07-18 17:52:58 +0000447 information on the Python profiler. The system's profile function
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000448 is called similarly to the system's trace function (see
Fred Drake72182022001-07-18 17:52:58 +0000449 \function{settrace()}), but it isn't called for each executed line
Fred Drake64d78632001-10-16 14:54:22 +0000450 of code (only on call and return, but the return event is reported
451 even when an exception has been set). The function is
452 thread-specific, but there is no way for the profiler to know about
453 context switches between threads, so it does not make sense to use
454 this in the presence of multiple threads.
Fred Drake72182022001-07-18 17:52:58 +0000455 Also, its return value is not used, so it can simply return
456 \code{None}.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000457\end{funcdesc}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000458
Jeremy Hyltonee5adfb2000-08-31 19:23:01 +0000459\begin{funcdesc}{setrecursionlimit}{limit}
Fred Drake72182022001-07-18 17:52:58 +0000460 Set the maximum depth of the Python interpreter stack to
461 \var{limit}. This limit prevents infinite recursion from causing an
462 overflow of the C stack and crashing Python.
Jeremy Hyltonee5adfb2000-08-31 19:23:01 +0000463
Fred Drake72182022001-07-18 17:52:58 +0000464 The highest possible limit is platform-dependent. A user may need
465 to set the limit higher when she has a program that requires deep
466 recursion and a platform that supports a higher limit. This should
467 be done with care, because a too-high limit can lead to a crash.
Fred Drake65faf112000-08-31 19:35:56 +0000468\end{funcdesc}
Jeremy Hyltonee5adfb2000-08-31 19:23:01 +0000469
Guido van Rossum3e5fe421998-06-10 17:57:44 +0000470\begin{funcdesc}{settrace}{tracefunc}
Fred Drake72182022001-07-18 17:52:58 +0000471 Set the system's trace function,\index{trace function} which allows
472 you to implement a Python source code debugger in Python. See
473 section \ref{debugger-hooks}, ``How It Works,'' in the chapter on
Fred Drake64d78632001-10-16 14:54:22 +0000474 the Python debugger.\index{debugger} The function is
475 thread-specific; for a debugger to support multiple threads, it must
476 be registered using \function{settrace()} for each thread being
Phillip J. Eby1884dda2004-08-05 12:13:46 +0000477 debugged. \note{The \function{settrace()} function is intended only
478 for implementing debuggers, profilers, coverage tools and the like.
Thomas Wouters0e3f5912006-08-11 14:57:12 +0000479 Its behavior is part of the implementation platform, rather than
Phillip J. Eby1884dda2004-08-05 12:13:46 +0000480 part of the language definition, and thus may not be available in
481 all Python implementations.}
Guido van Rossum3e5fe421998-06-10 17:57:44 +0000482\end{funcdesc}
Guido van Rossum3e5fe421998-06-10 17:57:44 +0000483
Martin v. Löwisf30d60e2004-06-08 08:17:44 +0000484\begin{funcdesc}{settscdump}{on_flag}
485 Activate dumping of VM measurements using the Pentium timestamp
486 counter, if \var{on_flag} is true. Deactivate these dumps if
487 \var{on_flag} is off. The function is available only if Python
Fred Drake7f354042004-06-08 14:01:27 +0000488 was compiled with \longprogramopt{with-tsc}. To understand the
489 output of this dump, read \file{Python/ceval.c} in the Python
490 sources.
Martin v. Löwisf30d60e2004-06-08 08:17:44 +0000491 \versionadded{2.4}
492\end{funcdesc}
493
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000494\begin{datadesc}{stdin}
495\dataline{stdout}
496\dataline{stderr}
497 File objects corresponding to the interpreter's standard input,
Fred Drake72182022001-07-18 17:52:58 +0000498 output and error streams. \code{stdin} is used for all interpreter
Neal Norwitzce96f692006-03-17 06:49:51 +0000499 input except for scripts. \code{stdout} is
500 used for the output of \keyword{print} and expression statements.
Fred Drake72182022001-07-18 17:52:58 +0000501 The interpreter's own prompts and (almost all of) its error messages
502 go to \code{stderr}. \code{stdout} and \code{stderr} needn't be
503 built-in file objects: any object is acceptable as long as it has a
504 \method{write()} method that takes a string argument. (Changing
505 these objects doesn't affect the standard I/O streams of processes
Fred Drake0fd72ee1998-03-08 05:43:51 +0000506 executed by \function{os.popen()}, \function{os.system()} or the
Fred Drake72182022001-07-18 17:52:58 +0000507 \function{exec*()} family of functions in the \refmodule{os}
508 module.)
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000509\end{datadesc}
510
Guido van Rossum3e5fe421998-06-10 17:57:44 +0000511\begin{datadesc}{__stdin__}
512\dataline{__stdout__}
513\dataline{__stderr__}
Fred Drake72182022001-07-18 17:52:58 +0000514 These objects contain the original values of \code{stdin},
515 \code{stderr} and \code{stdout} at the start of the program. They
516 are used during finalization, and could be useful to restore the
517 actual files to known working file objects in case they have been
518 overwritten with a broken object.
Guido van Rossum3e5fe421998-06-10 17:57:44 +0000519\end{datadesc}
520
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000521\begin{datadesc}{tracebacklimit}
Fred Drake72182022001-07-18 17:52:58 +0000522 When this variable is set to an integer value, it determines the
523 maximum number of levels of traceback information printed when an
524 unhandled exception occurs. The default is \code{1000}. When set
525 to \code{0} or less, all traceback information is suppressed and
526 only the exception type and value are printed.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000527\end{datadesc}
Guido van Rossum0a3c7531997-06-02 17:32:41 +0000528
529\begin{datadesc}{version}
Fred Drake72182022001-07-18 17:52:58 +0000530 A string containing the version number of the Python interpreter
531 plus additional information on the build number and compiler used.
532 It has a value of the form \code{'\var{version}
533 (\#\var{build_number}, \var{build_date}, \var{build_time})
534 [\var{compiler}]'}. The first three characters are used to identify
535 the version in the installation directories (where appropriate on
536 each platform). An example:
Fred Drake38e5d272000-04-03 20:13:55 +0000537
538\begin{verbatim}
539>>> import sys
540>>> sys.version
541'1.5.2 (#0 Apr 13 1999, 10:51:12) [MSC 32 bit (Intel)]'
542\end{verbatim}
543\end{datadesc}
544
Skip Montanaro8e790e72002-09-03 13:25:17 +0000545\begin{datadesc}{api_version}
546 The C API version for this interpreter. Programmers may find this useful
547 when debugging version conflicts between Python and extension
548 modules. \versionadded{2.3}
549\end{datadesc}
550
Fred Drake4d65d732000-04-13 16:54:17 +0000551\begin{datadesc}{version_info}
Fred Drake72182022001-07-18 17:52:58 +0000552 A tuple containing the five components of the version number:
553 \var{major}, \var{minor}, \var{micro}, \var{releaselevel}, and
554 \var{serial}. All values except \var{releaselevel} are integers;
555 the release level is \code{'alpha'}, \code{'beta'},
556 \code{'candidate'}, or \code{'final'}. The \code{version_info}
557 value corresponding to the Python version 2.0 is \code{(2, 0, 0,
558 'final', 0)}.
559 \versionadded{2.0}
Fred Drake4d65d732000-04-13 16:54:17 +0000560\end{datadesc}
561
Fred Drakec05fc7d2001-09-04 18:18:36 +0000562\begin{datadesc}{warnoptions}
563 This is an implementation detail of the warnings framework; do not
564 modify this value. Refer to the \refmodule{warnings} module for
565 more information on the warnings framework.
566\end{datadesc}
567
Fred Drake38e5d272000-04-03 20:13:55 +0000568\begin{datadesc}{winver}
Fred Drake72182022001-07-18 17:52:58 +0000569 The version number used to form registry keys on Windows platforms.
570 This is stored as string resource 1000 in the Python DLL. The value
571 is normally the first three characters of \constant{version}. It is
572 provided in the \module{sys} module for informational purposes;
573 modifying this value has no effect on the registry keys used by
574 Python.
575 Availability: Windows.
Guido van Rossum0a3c7531997-06-02 17:32:41 +0000576\end{datadesc}
Skip Montanaro8a797272002-03-27 17:29:50 +0000577
578
579\begin{seealso}
580 \seemodule{site}
581 {This describes how to use .pth files to extend \code{sys.path}.}
582\end{seealso}