CodeCrafters IT Innovation | Bansal Computer Center, Dhuri – IT & AI Courses
Loading...

Python Sys Module

Introduction & Interpreter Information

What is sys Module?

The sys module is a built-in Python module that provides access to system-specific parameters and functions. It allows interaction with: Python interpreter, Command line, Memory, Input / Output, and System environment.

import sys

Python Interpreter Information

Platform & System Information

sys.platform: Returns the operating system name.

win32Windows
linuxLinux
darwinmacOS

Command Line & Program Termination

Command Line Arguments (sys.argv)

sys.argv is a list that stores command line arguments.

IndexMeaning
argv[0]Program name
argv[1]First argument
argv[2]Second argument

Program Termination (sys.exit())

Stops the program immediately. Code after exit() will not execute.

sys.exit()
# With message:
sys.exit("Program Ended")

Module Search Path & IO Streams

Module Search Path (sys.path)

Returns a list of directories where Python searches for modules. Useful for importing custom modules.

print(sys.path)
# Adding a path:
sys.path.append("D:/myfolder")

Standard Input / Output / Error Streams

Memory Management & Reference Handling

The sys module provides essential functions to analyze how Python handles objects in memory and manages resources.

Recursion Limits

Memory & References

import sys
# Managing Recursion
print(sys.getrecursionlimit())   # Check current limit
sys.setrecursionlimit(2000)      # Set new limit carefully

System Limits & Advanced Handling

Simple Example Program

import sys
print("Python Version:", sys.version)
print("Platform:", sys.platform)
print("Arguments:", sys.argv)
print("Memory Size of 10:", sys.getsizeof(10))

Quick Revision & One-Liners

One-Line Exam Answers:
sys module: Provides access to system-specific parameters and interpreter info.
sys.argv: Stores command-line arguments.
sys.exit(): Terminates the program.
sys.path: Module search directories.
sys.getsizeof(): Returns memory size.

FunctionPurpose
sys.versionPython version
sys.platformOS info
sys.argvCommand arguments
sys.exitStop program
sys.pathModule paths
sys.stdinInput
sys.stdoutOutput
sys.stderrErrors
sys.getsizeofMemory size
sys.maxsizeMax integer

What Students Say

Here are our students...

Phone

Contact Us

Empower your tech dreams with us. Get in touch!

  • Partner brand
  • Partner brand
  • Partner brand
  • Partner brand
  • Partner brand