The sys Module

The sys module contains interpreter-related exports. It also provides access to some environment components, such as the command line, standard streams, and so on.


Command-line argument strings list: [command, arguments...]. Like C’s argv array.


Indicates the native byte-order (e.g., big for big-endian).


Tuple of string names of C modules compiled into this Python interpreter.


String containing the Python interpreter copyright.


Python DLL integer handle; Windows only (see the Python Library Reference).


Called by Python to display result values in interactive sessions; assign sys.displayhook to a one-argument function to customize output.

excepthook(type, value, traceback)

Called by Python to display uncaught exception details to stderr; assign sys.excepthook to a three-argument function to customize exception displays.


Returns tuple of three values describing the exception currently being handled (type, value, traceback), where type is the exception class, value is the instance of the exception class raised, and traceback is an object that gives access to the runtime call stack as it existed when the exception occurred. Specific to current thread. Subsumes exc_type, exc_value, and exc_traceback in Python 1.5 and later (all three of which are removed completely in Python 3.0). See the traceback module in the Python Library Reference for processing traceback objects, and The try Statement for more ...

Get Python Pocket Reference, 4th Edition now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.