Python sys Module
Example
Get Python version and command-line arguments:
import sys
print(f'Python version: {sys.version}')
print(f'Platform: {sys.platform}')
Try it Yourself »
Definition and Usage
The sys module provides access to system-specific parameters and functions that interact with the Python interpreter.
Use it to access command-line arguments, control the Python path, exit programs, or query interpreter settings.
Members
Member | Description |
---|---|
argv | List of command-line arguments passed to the script. |
builtin_module_names | Tuple of names of modules compiled into this Python interpreter. |
byteorder | Native byte order ('big' or 'little'). |
copyright | Copyright information for the Python interpreter. |
exc_info() | Return information about the currently handled exception. |
exec_prefix | Prefix for platform-dependent Python files. |
executable | Absolute path of the Python interpreter executable. |
exit() | Exit the program with a given status (default 0). |
flags | Named tuple of command-line flags. |
getdefaultencoding() | Return the default string encoding. |
getrecursionlimit() | Return the current recursion limit. |
getsizeof() | Return the size of an object in bytes. |
implementation | Object with information about the Python implementation. |
maxsize | Maximum value a variable of type Py_ssize_t can take. |
modules | Dictionary mapping module names to loaded modules. |
path | List of strings that specifies the search path for modules. |
platform | Platform identifier string (e.g., 'win32', 'linux'). |
prefix | Prefix for platform-independent Python files. |
setrecursionlimit() | Set the maximum recursion depth. |
stderr | Standard error stream (file object). |
stdin | Standard input stream (file object). |
stdout | Standard output stream (file object). |
version | Python version as a string. |
version_info | Python version as a named tuple. |