Bharani Park Matric Hr Sec School
Computer Science – Python Modules (sys, os, getopt)
1. sys Module
The sys module provides access to variables and functions used by the Python interpreter. It is
mainly used for handling command-line arguments using [Link]. [Link] is a list of
command-line arguments passed to the Python program. [Link][0] → Name of the Python
program [Link][1] → Next argument (C++ file)
Element Description
[Link] List of command-line arguments
[Link][0] Name of the Python program
[Link][1] Next argument (C++ file)
Example: import sys → print([Link])
2. os Module
The os module provides a way of using operating system dependent functionality. It allows
interaction with the system where Python is running. [Link]() is used to execute system
commands such as compiling a C++ program.
Function Purpose
[Link]() Executes system command
g++ Compiler used to compile C++ programs
Example: [Link]('g++ ' + cppfile + ' -o ' + exefile)
3. getopt Module
The getopt module helps to parse command-line options and arguments. It splits the command-line
input into options and values. Syntax: [Link](argv, options, [long_options]) It returns two
values: opts – list of parsed options args – list of remaining arguments
Parameter Description
argv List of arguments
options Short options like -i
long_options Long options like --input
opts Parsed options
args Remaining arguments
Example: opts, args = [Link](argv, 'i:', ['ifile='])