10/23/26About 1 minAbout 208 words
Concept: The sys module
| Function / attribute | Description | Example |
|---|---|---|
| sys.argv | List of command-line arguments; sys.argv[0] is the script name. | ./backup.py /data → sys.argv[1] is '/data' |
| sys.exit(code) | Stops the script with an exit code (0 = success, anything else = error). | sys.exit(1) |
| sys.stdin | The standard input stream; useful for reading piped input. | for line in sys.stdin: |
| sys.stdout | The standard output stream. | sys.stdout.write("OK\n") |
| sys.stderr | The standard error stream; use it for error messages. | print("Error!", file=sys.stderr) |
| sys.platform | Identifies the platform: 'linux', 'win32', 'darwin', ... | if sys.platform == "linux": |
| sys.version | String with the version of the Python interpreter. | sys.version → '3.14.0 (main, ...)' |
| sys.version_info | Version as a tuple-like object; handy for checking a minimum version. | if sys.version_info < (3, 10): |
| sys.executable | Absolute path of the Python interpreter running the script. | sys.executable → '/usr/bin/python3' |
| sys.path | List of directories Python searches when importing modules. | print(sys.path) |