blob: 6b88d613e2bed0c1ff4bcda2ee41298e8db7b628 [file] [log] [blame]
Georg Brandl8ec7f652007-08-15 14:28:01 +00001
2:mod:`sys` --- System-specific parameters and functions
3=======================================================
4
5.. module:: sys
6 :synopsis: Access system-specific parameters and functions.
7
8
9This module provides access to some variables used or maintained by the
10interpreter and to functions that interact strongly with the interpreter. It is
11always available.
12
13
14.. data:: argv
15
16 The list of command line arguments passed to a Python script. ``argv[0]`` is the
17 script name (it is operating system dependent whether this is a full pathname or
18 not). If the command was executed using the :option:`-c` command line option to
19 the interpreter, ``argv[0]`` is set to the string ``'-c'``. If no script name
20 was passed to the Python interpreter, ``argv[0]`` is the empty string.
21
22 To loop over the standard input, or the list of files given on the
23 command line, see the :mod:`fileinput` module.
24
25
26.. data:: byteorder
27
28 An indicator of the native byte order. This will have the value ``'big'`` on
29 big-endian (most-significant byte first) platforms, and ``'little'`` on
30 little-endian (least-significant byte first) platforms.
31
32 .. versionadded:: 2.0
33
34
35.. data:: subversion
36
37 A triple (repo, branch, version) representing the Subversion information of the
38 Python interpreter. *repo* is the name of the repository, ``'CPython'``.
39 *branch* is a string of one of the forms ``'trunk'``, ``'branches/name'`` or
40 ``'tags/name'``. *version* is the output of ``svnversion``, if the interpreter
41 was built from a Subversion checkout; it contains the revision number (range)
42 and possibly a trailing 'M' if there were local modifications. If the tree was
43 exported (or svnversion was not available), it is the revision of
44 ``Include/patchlevel.h`` if the branch is a tag. Otherwise, it is ``None``.
45
46 .. versionadded:: 2.5
47
48
49.. data:: builtin_module_names
50
51 A tuple of strings giving the names of all modules that are compiled into this
52 Python interpreter. (This information is not available in any other way ---
53 ``modules.keys()`` only lists the imported modules.)
54
55
56.. data:: copyright
57
58 A string containing the copyright pertaining to the Python interpreter.
59
60
61.. function:: _current_frames()
62
63 Return a dictionary mapping each thread's identifier to the topmost stack frame
64 currently active in that thread at the time the function is called. Note that
65 functions in the :mod:`traceback` module can build the call stack given such a
66 frame.
67
68 This is most useful for debugging deadlock: this function does not require the
69 deadlocked threads' cooperation, and such threads' call stacks are frozen for as
70 long as they remain deadlocked. The frame returned for a non-deadlocked thread
71 may bear no relationship to that thread's current activity by the time calling
72 code examines the frame.
73
74 This function should be used for internal and specialized purposes only.
75
76 .. versionadded:: 2.5
77
78
79.. data:: dllhandle
80
81 Integer specifying the handle of the Python DLL. Availability: Windows.
82
83
84.. function:: displayhook(value)
85
86 If *value* is not ``None``, this function prints it to ``sys.stdout``, and saves
87 it in ``__builtin__._``.
88
Georg Brandl584265b2007-12-02 14:58:50 +000089 ``sys.displayhook`` is called on the result of evaluating an :term:`expression`
90 entered in an interactive Python session. The display of these values can be
91 customized by assigning another one-argument function to ``sys.displayhook``.
Georg Brandl8ec7f652007-08-15 14:28:01 +000092
93
94.. function:: excepthook(type, value, traceback)
95
96 This function prints out a given traceback and exception to ``sys.stderr``.
97
98 When an exception is raised and uncaught, the interpreter calls
99 ``sys.excepthook`` with three arguments, the exception class, exception
100 instance, and a traceback object. In an interactive session this happens just
101 before control is returned to the prompt; in a Python program this happens just
102 before the program exits. The handling of such top-level exceptions can be
103 customized by assigning another three-argument function to ``sys.excepthook``.
104
105
106.. data:: __displayhook__
107 __excepthook__
108
109 These objects contain the original values of ``displayhook`` and ``excepthook``
110 at the start of the program. They are saved so that ``displayhook`` and
111 ``excepthook`` can be restored in case they happen to get replaced with broken
112 objects.
113
114
115.. function:: exc_info()
116
117 This function returns a tuple of three values that give information about the
118 exception that is currently being handled. The information returned is specific
119 both to the current thread and to the current stack frame. If the current stack
120 frame is not handling an exception, the information is taken from the calling
121 stack frame, or its caller, and so on until a stack frame is found that is
122 handling an exception. Here, "handling an exception" is defined as "executing
123 or having executed an except clause." For any stack frame, only information
124 about the most recently handled exception is accessible.
125
126 .. index:: object: traceback
127
128 If no exception is being handled anywhere on the stack, a tuple containing three
129 ``None`` values is returned. Otherwise, the values returned are ``(type, value,
130 traceback)``. Their meaning is: *type* gets the exception type of the exception
131 being handled (a class object); *value* gets the exception parameter (its
132 :dfn:`associated value` or the second argument to :keyword:`raise`, which is
133 always a class instance if the exception type is a class object); *traceback*
134 gets a traceback object (see the Reference Manual) which encapsulates the call
135 stack at the point where the exception originally occurred.
136
137 If :func:`exc_clear` is called, this function will return three ``None`` values
138 until either another exception is raised in the current thread or the execution
139 stack returns to a frame where another exception is being handled.
140
141 .. warning::
142
143 Assigning the *traceback* return value to a local variable in a function that is
144 handling an exception will cause a circular reference. This will prevent
145 anything referenced by a local variable in the same function or by the traceback
146 from being garbage collected. Since most functions don't need access to the
147 traceback, the best solution is to use something like ``exctype, value =
148 sys.exc_info()[:2]`` to extract only the exception type and value. If you do
149 need the traceback, make sure to delete it after use (best done with a
150 :keyword:`try` ... :keyword:`finally` statement) or to call :func:`exc_info` in
151 a function that does not itself handle an exception.
152
153 .. note::
154
155 Beginning with Python 2.2, such cycles are automatically reclaimed when garbage
156 collection is enabled and they become unreachable, but it remains more efficient
157 to avoid creating cycles.
158
159
160.. function:: exc_clear()
161
162 This function clears all information relating to the current or last exception
163 that occurred in the current thread. After calling this function,
164 :func:`exc_info` will return three ``None`` values until another exception is
165 raised in the current thread or the execution stack returns to a frame where
166 another exception is being handled.
167
168 This function is only needed in only a few obscure situations. These include
169 logging and error handling systems that report information on the last or
170 current exception. This function can also be used to try to free resources and
171 trigger object finalization, though no guarantee is made as to what objects will
172 be freed, if any.
173
174 .. versionadded:: 2.3
175
176
177.. data:: exc_type
178 exc_value
179 exc_traceback
180
181 .. deprecated:: 1.5
182 Use :func:`exc_info` instead.
183
184 Since they are global variables, they are not specific to the current thread, so
185 their use is not safe in a multi-threaded program. When no exception is being
186 handled, ``exc_type`` is set to ``None`` and the other two are undefined.
187
188
189.. data:: exec_prefix
190
191 A string giving the site-specific directory prefix where the platform-dependent
192 Python files are installed; by default, this is also ``'/usr/local'``. This can
193 be set at build time with the :option:`--exec-prefix` argument to the
194 :program:`configure` script. Specifically, all configuration files (e.g. the
195 :file:`pyconfig.h` header file) are installed in the directory ``exec_prefix +
196 '/lib/pythonversion/config'``, and shared library modules are installed in
197 ``exec_prefix + '/lib/pythonversion/lib-dynload'``, where *version* is equal to
198 ``version[:3]``.
199
200
201.. data:: executable
202
203 A string giving the name of the executable binary for the Python interpreter, on
204 systems where this makes sense.
205
206
207.. function:: exit([arg])
208
209 Exit from Python. This is implemented by raising the :exc:`SystemExit`
210 exception, so cleanup actions specified by finally clauses of :keyword:`try`
211 statements are honored, and it is possible to intercept the exit attempt at an
212 outer level. The optional argument *arg* can be an integer giving the exit
213 status (defaulting to zero), or another type of object. If it is an integer,
214 zero is considered "successful termination" and any nonzero value is considered
215 "abnormal termination" by shells and the like. Most systems require it to be in
216 the range 0-127, and produce undefined results otherwise. Some systems have a
217 convention for assigning specific meanings to specific exit codes, but these are
218 generally underdeveloped; Unix programs generally use 2 for command line syntax
219 errors and 1 for all other kind of errors. If another type of object is passed,
220 ``None`` is equivalent to passing zero, and any other object is printed to
221 ``sys.stderr`` and results in an exit code of 1. In particular,
222 ``sys.exit("some error message")`` is a quick way to exit a program when an
223 error occurs.
224
225
226.. data:: exitfunc
227
228 This value is not actually defined by the module, but can be set by the user (or
229 by a program) to specify a clean-up action at program exit. When set, it should
230 be a parameterless function. This function will be called when the interpreter
231 exits. Only one function may be installed in this way; to allow multiple
232 functions which will be called at termination, use the :mod:`atexit` module.
233
234 .. note::
235
236 The exit function is not called when the program is killed by a signal, when a
237 Python fatal internal error is detected, or when ``os._exit()`` is called.
238
239 .. deprecated:: 2.4
240 Use :mod:`atexit` instead.
241
242
Christian Heimesf31b69f2008-01-14 03:42:48 +0000243.. data:: flags
244
245 The struct sequence *flags* exposes the status of command line flags. The
246 attributes are read only.
247
248 +------------------------------+------------------------------------------+
249 | attribute | flag |
250 +==============================+==========================================+
251 | :const:`debug` | -d |
252 +------------------------------+------------------------------------------+
253 | :const:`py3k_warning` | -3 |
254 +------------------------------+------------------------------------------+
255 | :const:`division_warning` | -Q |
256 +------------------------------+------------------------------------------+
257 | :const:`division_new` | -Qnew |
258 +------------------------------+------------------------------------------+
259 | :const:`inspect` | -i |
260 +------------------------------+------------------------------------------+
261 | :const:`interactive` | -i |
262 +------------------------------+------------------------------------------+
263 | :const:`optimize` | -O or -OO |
264 +------------------------------+------------------------------------------+
265 | :const:`dont_write_bytecode` | -B |
266 +------------------------------+------------------------------------------+
267 | :const:`no_site` | -S |
268 +------------------------------+------------------------------------------+
Andrew M. Kuchling7ce9b182008-01-15 01:29:16 +0000269 | :const:`ignore_environment` | -E |
Christian Heimesf31b69f2008-01-14 03:42:48 +0000270 +------------------------------+------------------------------------------+
271 | :const:`tabcheck` | -t or -tt |
272 +------------------------------+------------------------------------------+
273 | :const:`verbose` | -v |
274 +------------------------------+------------------------------------------+
275 | :const:`unicode` | -U |
276 +------------------------------+------------------------------------------+
277
278 .. versionadded:: 2.6
279
280
Christian Heimesdfdfaab2007-12-01 11:20:10 +0000281.. data:: float_info
282
Christian Heimesc94e2b52008-01-14 04:13:37 +0000283 A structseq holding information about the float type. It contains low level
Christian Heimesdfdfaab2007-12-01 11:20:10 +0000284 information about the precision and internal representation. Please study
285 your system's :file:`float.h` for more information.
286
287 +---------------------+--------------------------------------------------+
Christian Heimesc94e2b52008-01-14 04:13:37 +0000288 | attribute | explanation |
Christian Heimesdfdfaab2007-12-01 11:20:10 +0000289 +=====================+==================================================+
290 | :const:`epsilon` | Difference between 1 and the next representable |
291 | | floating point number |
292 +---------------------+--------------------------------------------------+
293 | :const:`dig` | digits (see :file:`float.h`) |
294 +---------------------+--------------------------------------------------+
295 | :const:`mant_dig` | mantissa digits (see :file:`float.h`) |
296 +---------------------+--------------------------------------------------+
297 | :const:`max` | maximum representable finite float |
298 +---------------------+--------------------------------------------------+
299 | :const:`max_exp` | maximum int e such that radix**(e-1) is in the |
300 | | range of finite representable floats |
301 +---------------------+--------------------------------------------------+
302 | :const:`max_10_exp` | maximum int e such that 10**e is in the |
303 | | range of finite representable floats |
304 +---------------------+--------------------------------------------------+
305 | :const:`min` | Minimum positive normalizer float |
306 +---------------------+--------------------------------------------------+
307 | :const:`min_exp` | minimum int e such that radix**(e-1) is a |
308 | | normalized float |
309 +---------------------+--------------------------------------------------+
310 | :const:`min_10_exp` | minimum int e such that 10**e is a normalized |
311 | | float |
312 +---------------------+--------------------------------------------------+
313 | :const:`radix` | radix of exponent |
314 +---------------------+--------------------------------------------------+
315 | :const:`rounds` | addition rounds (see :file:`float.h`) |
316 +---------------------+--------------------------------------------------+
317
318 .. note::
319
320 The information in the table is simplified.
321
Christian Heimes3e76d932007-12-01 15:40:22 +0000322 .. versionadded:: 2.6
323
Christian Heimesdfdfaab2007-12-01 11:20:10 +0000324
Georg Brandl8ec7f652007-08-15 14:28:01 +0000325.. function:: getcheckinterval()
326
327 Return the interpreter's "check interval"; see :func:`setcheckinterval`.
328
329 .. versionadded:: 2.3
330
331
332.. function:: getdefaultencoding()
333
334 Return the name of the current default string encoding used by the Unicode
335 implementation.
336
337 .. versionadded:: 2.0
338
339
340.. function:: getdlopenflags()
341
342 Return the current value of the flags that are used for :cfunc:`dlopen` calls.
343 The flag constants are defined in the :mod:`dl` and :mod:`DLFCN` modules.
344 Availability: Unix.
345
346 .. versionadded:: 2.2
347
348
349.. function:: getfilesystemencoding()
350
351 Return the name of the encoding used to convert Unicode filenames into system
352 file names, or ``None`` if the system default encoding is used. The result value
353 depends on the operating system:
354
355 * On Windows 9x, the encoding is "mbcs".
356
357 * On Mac OS X, the encoding is "utf-8".
358
359 * On Unix, the encoding is the user's preference according to the result of
360 nl_langinfo(CODESET), or :const:`None` if the ``nl_langinfo(CODESET)`` failed.
361
362 * On Windows NT+, file names are Unicode natively, so no conversion is
363 performed. :func:`getfilesystemencoding` still returns ``'mbcs'``, as this is
364 the encoding that applications should use when they explicitly want to convert
365 Unicode strings to byte strings that are equivalent when used as file names.
366
367 .. versionadded:: 2.3
368
369
370.. function:: getrefcount(object)
371
372 Return the reference count of the *object*. The count returned is generally one
373 higher than you might expect, because it includes the (temporary) reference as
374 an argument to :func:`getrefcount`.
375
376
377.. function:: getrecursionlimit()
378
379 Return the current value of the recursion limit, the maximum depth of the Python
380 interpreter stack. This limit prevents infinite recursion from causing an
381 overflow of the C stack and crashing Python. It can be set by
382 :func:`setrecursionlimit`.
383
384
385.. function:: _getframe([depth])
386
387 Return a frame object from the call stack. If optional integer *depth* is
388 given, return the frame object that many calls below the top of the stack. If
389 that is deeper than the call stack, :exc:`ValueError` is raised. The default
390 for *depth* is zero, returning the frame at the top of the call stack.
391
392 This function should be used for internal and specialized purposes only.
393
394
395.. function:: getwindowsversion()
396
397 Return a tuple containing five components, describing the Windows version
398 currently running. The elements are *major*, *minor*, *build*, *platform*, and
399 *text*. *text* contains a string while all other values are integers.
400
401 *platform* may be one of the following values:
402
403 +-----------------------------------------+-----------------------+
404 | Constant | Platform |
405 +=========================================+=======================+
406 | :const:`0 (VER_PLATFORM_WIN32s)` | Win32s on Windows 3.1 |
407 +-----------------------------------------+-----------------------+
408 | :const:`1 (VER_PLATFORM_WIN32_WINDOWS)` | Windows 95/98/ME |
409 +-----------------------------------------+-----------------------+
410 | :const:`2 (VER_PLATFORM_WIN32_NT)` | Windows NT/2000/XP |
411 +-----------------------------------------+-----------------------+
412 | :const:`3 (VER_PLATFORM_WIN32_CE)` | Windows CE |
413 +-----------------------------------------+-----------------------+
414
415 This function wraps the Win32 :cfunc:`GetVersionEx` function; see the Microsoft
416 documentation for more information about these fields.
417
418 Availability: Windows.
419
420 .. versionadded:: 2.3
421
422
423.. data:: hexversion
424
425 The version number encoded as a single integer. This is guaranteed to increase
426 with each version, including proper support for non-production releases. For
427 example, to test that the Python interpreter is at least version 1.5.2, use::
428
429 if sys.hexversion >= 0x010502F0:
430 # use some advanced feature
431 ...
432 else:
433 # use an alternative implementation or warn the user
434 ...
435
436 This is called ``hexversion`` since it only really looks meaningful when viewed
437 as the result of passing it to the built-in :func:`hex` function. The
438 ``version_info`` value may be used for a more human-friendly encoding of the
439 same information.
440
441 .. versionadded:: 1.5.2
442
443
444.. data:: last_type
445 last_value
446 last_traceback
447
448 These three variables are not always defined; they are set when an exception is
449 not handled and the interpreter prints an error message and a stack traceback.
450 Their intended use is to allow an interactive user to import a debugger module
451 and engage in post-mortem debugging without having to re-execute the command
452 that caused the error. (Typical use is ``import pdb; pdb.pm()`` to enter the
453 post-mortem debugger; see chapter :ref:`debugger` for
454 more information.)
455
456 The meaning of the variables is the same as that of the return values from
457 :func:`exc_info` above. (Since there is only one interactive thread,
458 thread-safety is not a concern for these variables, unlike for ``exc_type``
459 etc.)
460
461
462.. data:: maxint
463
464 The largest positive integer supported by Python's regular integer type. This
465 is at least 2\*\*31-1. The largest negative integer is ``-maxint-1`` --- the
466 asymmetry results from the use of 2's complement binary arithmetic.
467
468
469.. data:: maxunicode
470
471 An integer giving the largest supported code point for a Unicode character. The
472 value of this depends on the configuration option that specifies whether Unicode
473 characters are stored as UCS-2 or UCS-4.
474
475
476.. data:: modules
477
478 .. index:: builtin: reload
479
480 This is a dictionary that maps module names to modules which have already been
481 loaded. This can be manipulated to force reloading of modules and other tricks.
482 Note that removing a module from this dictionary is *not* the same as calling
483 :func:`reload` on the corresponding module object.
484
485
486.. data:: path
487
488 .. index:: triple: module; search; path
489
490 A list of strings that specifies the search path for modules. Initialized from
491 the environment variable :envvar:`PYTHONPATH`, plus an installation-dependent
492 default.
493
494 As initialized upon program startup, the first item of this list, ``path[0]``,
495 is the directory containing the script that was used to invoke the Python
496 interpreter. If the script directory is not available (e.g. if the interpreter
497 is invoked interactively or if the script is read from standard input),
498 ``path[0]`` is the empty string, which directs Python to search modules in the
499 current directory first. Notice that the script directory is inserted *before*
500 the entries inserted as a result of :envvar:`PYTHONPATH`.
501
502 A program is free to modify this list for its own purposes.
503
504 .. versionchanged:: 2.3
505 Unicode strings are no longer ignored.
506
507
508.. data:: platform
509
510 This string contains a platform identifier, e.g. ``'sunos5'`` or ``'linux1'``.
511 This can be used to append platform-specific components to ``path``, for
512 instance.
513
514
515.. data:: prefix
516
517 A string giving the site-specific directory prefix where the platform
518 independent Python files are installed; by default, this is the string
519 ``'/usr/local'``. This can be set at build time with the :option:`--prefix`
520 argument to the :program:`configure` script. The main collection of Python
521 library modules is installed in the directory ``prefix + '/lib/pythonversion'``
522 while the platform independent header files (all except :file:`pyconfig.h`) are
523 stored in ``prefix + '/include/pythonversion'``, where *version* is equal to
524 ``version[:3]``.
525
526
527.. data:: ps1
528 ps2
529
530 .. index::
531 single: interpreter prompts
532 single: prompts, interpreter
533
534 Strings specifying the primary and secondary prompt of the interpreter. These
535 are only defined if the interpreter is in interactive mode. Their initial
536 values in this case are ``'>>> '`` and ``'... '``. If a non-string object is
537 assigned to either variable, its :func:`str` is re-evaluated each time the
538 interpreter prepares to read a new interactive command; this can be used to
539 implement a dynamic prompt.
540
541
Christian Heimesd7b33372007-11-28 08:02:36 +0000542.. data:: py3kwarning
543
544 Bool containing the status of the Python 3.0 warning flag. It's ``True``
545 when Python is started with the -3 option.
546
547
Georg Brandl2da0fce2008-01-07 17:09:35 +0000548.. data:: dont_write_bytecode
549
550 If this is true, Python won't try to write ``.pyc`` or ``.pyo`` files on the
551 import of source modules. This value is initially set to ``True`` or ``False``
552 depending on the ``-B`` command line option and the ``PYTHONDONTWRITEBYTECODE``
553 environment variable, but you can set it yourself to control bytecode file
554 generation.
555
556 .. versionadded:: 2.6
557
558
Georg Brandl8ec7f652007-08-15 14:28:01 +0000559.. function:: setcheckinterval(interval)
560
561 Set the interpreter's "check interval". This integer value determines how often
562 the interpreter checks for periodic things such as thread switches and signal
563 handlers. The default is ``100``, meaning the check is performed every 100
564 Python virtual instructions. Setting it to a larger value may increase
565 performance for programs using threads. Setting it to a value ``<=`` 0 checks
566 every virtual instruction, maximizing responsiveness as well as overhead.
567
568
569.. function:: setdefaultencoding(name)
570
571 Set the current default string encoding used by the Unicode implementation. If
572 *name* does not match any available encoding, :exc:`LookupError` is raised.
573 This function is only intended to be used by the :mod:`site` module
574 implementation and, where needed, by :mod:`sitecustomize`. Once used by the
575 :mod:`site` module, it is removed from the :mod:`sys` module's namespace.
576
Georg Brandlb19be572007-12-29 10:57:00 +0000577 .. Note that :mod:`site` is not imported if the :option:`-S` option is passed
578 to the interpreter, in which case this function will remain available.
Georg Brandl8ec7f652007-08-15 14:28:01 +0000579
580 .. versionadded:: 2.0
581
582
583.. function:: setdlopenflags(n)
584
585 Set the flags used by the interpreter for :cfunc:`dlopen` calls, such as when
586 the interpreter loads extension modules. Among other things, this will enable a
587 lazy resolving of symbols when importing a module, if called as
588 ``sys.setdlopenflags(0)``. To share symbols across extension modules, call as
589 ``sys.setdlopenflags(dl.RTLD_NOW | dl.RTLD_GLOBAL)``. Symbolic names for the
590 flag modules can be either found in the :mod:`dl` module, or in the :mod:`DLFCN`
591 module. If :mod:`DLFCN` is not available, it can be generated from
592 :file:`/usr/include/dlfcn.h` using the :program:`h2py` script. Availability:
593 Unix.
594
595 .. versionadded:: 2.2
596
597
598.. function:: setprofile(profilefunc)
599
600 .. index::
601 single: profile function
602 single: profiler
603
604 Set the system's profile function, which allows you to implement a Python source
605 code profiler in Python. See chapter :ref:`profile` for more information on the
606 Python profiler. The system's profile function is called similarly to the
607 system's trace function (see :func:`settrace`), but it isn't called for each
608 executed line of code (only on call and return, but the return event is reported
609 even when an exception has been set). The function is thread-specific, but
610 there is no way for the profiler to know about context switches between threads,
611 so it does not make sense to use this in the presence of multiple threads. Also,
612 its return value is not used, so it can simply return ``None``.
613
614
615.. function:: setrecursionlimit(limit)
616
617 Set the maximum depth of the Python interpreter stack to *limit*. This limit
618 prevents infinite recursion from causing an overflow of the C stack and crashing
619 Python.
620
621 The highest possible limit is platform-dependent. A user may need to set the
622 limit higher when she has a program that requires deep recursion and a platform
623 that supports a higher limit. This should be done with care, because a too-high
624 limit can lead to a crash.
625
626
627.. function:: settrace(tracefunc)
628
629 .. index::
630 single: trace function
631 single: debugger
632
633 Set the system's trace function, which allows you to implement a Python
634 source code debugger in Python. See section :ref:`debugger-hooks` in the
635 chapter on the Python debugger. The function is thread-specific; for a
636 debugger to support multiple threads, it must be registered using
637 :func:`settrace` for each thread being debugged.
638
639 .. note::
640
641 The :func:`settrace` function is intended only for implementing debuggers,
642 profilers, coverage tools and the like. Its behavior is part of the
643 implementation platform, rather than part of the language definition, and thus
644 may not be available in all Python implementations.
645
646
647.. function:: settscdump(on_flag)
648
649 Activate dumping of VM measurements using the Pentium timestamp counter, if
650 *on_flag* is true. Deactivate these dumps if *on_flag* is off. The function is
651 available only if Python was compiled with :option:`--with-tsc`. To understand
652 the output of this dump, read :file:`Python/ceval.c` in the Python sources.
653
654 .. versionadded:: 2.4
655
656
657.. data:: stdin
658 stdout
659 stderr
660
661 .. index::
662 builtin: input
663 builtin: raw_input
664
665 File objects corresponding to the interpreter's standard input, output and error
666 streams. ``stdin`` is used for all interpreter input except for scripts but
667 including calls to :func:`input` and :func:`raw_input`. ``stdout`` is used for
Georg Brandl584265b2007-12-02 14:58:50 +0000668 the output of :keyword:`print` and :term:`expression` statements and for the
669 prompts of :func:`input` and :func:`raw_input`. The interpreter's own prompts
670 and (almost all of) its error messages go to ``stderr``. ``stdout`` and
671 ``stderr`` needn't be built-in file objects: any object is acceptable as long
672 as it has a :meth:`write` method that takes a string argument. (Changing these
673 objects doesn't affect the standard I/O streams of processes executed by
Georg Brandl8ec7f652007-08-15 14:28:01 +0000674 :func:`os.popen`, :func:`os.system` or the :func:`exec\*` family of functions in
675 the :mod:`os` module.)
676
677
678.. data:: __stdin__
679 __stdout__
680 __stderr__
681
682 These objects contain the original values of ``stdin``, ``stderr`` and
683 ``stdout`` at the start of the program. They are used during finalization, and
684 could be useful to restore the actual files to known working file objects in
685 case they have been overwritten with a broken object.
686
687
688.. data:: tracebacklimit
689
690 When this variable is set to an integer value, it determines the maximum number
691 of levels of traceback information printed when an unhandled exception occurs.
692 The default is ``1000``. When set to ``0`` or less, all traceback information
693 is suppressed and only the exception type and value are printed.
694
695
696.. data:: version
697
698 A string containing the version number of the Python interpreter plus additional
699 information on the build number and compiler used. It has a value of the form
700 ``'version (#build_number, build_date, build_time) [compiler]'``. The first
701 three characters are used to identify the version in the installation
702 directories (where appropriate on each platform). An example::
703
704 >>> import sys
705 >>> sys.version
706 '1.5.2 (#0 Apr 13 1999, 10:51:12) [MSC 32 bit (Intel)]'
707
708
709.. data:: api_version
710
711 The C API version for this interpreter. Programmers may find this useful when
712 debugging version conflicts between Python and extension modules.
713
714 .. versionadded:: 2.3
715
716
717.. data:: version_info
718
719 A tuple containing the five components of the version number: *major*, *minor*,
720 *micro*, *releaselevel*, and *serial*. All values except *releaselevel* are
721 integers; the release level is ``'alpha'``, ``'beta'``, ``'candidate'``, or
722 ``'final'``. The ``version_info`` value corresponding to the Python version 2.0
723 is ``(2, 0, 0, 'final', 0)``.
724
725 .. versionadded:: 2.0
726
727
728.. data:: warnoptions
729
730 This is an implementation detail of the warnings framework; do not modify this
731 value. Refer to the :mod:`warnings` module for more information on the warnings
732 framework.
733
734
735.. data:: winver
736
737 The version number used to form registry keys on Windows platforms. This is
738 stored as string resource 1000 in the Python DLL. The value is normally the
739 first three characters of :const:`version`. It is provided in the :mod:`sys`
740 module for informational purposes; modifying this value has no effect on the
741 registry keys used by Python. Availability: Windows.
742
743
744.. seealso::
745
746 Module :mod:`site`
747 This describes how to use .pth files to extend ``sys.path``.
748