0% found this document useful (0 votes)
2 views2 pages

Python Modules Final Corrected Notes

The document provides an overview of three Python modules: sys, os, and getopt. The sys module is used for handling command-line arguments, the os module allows interaction with the operating system to execute commands, and the getopt module helps parse command-line options and arguments. Examples of usage for each module are included to illustrate their functionalities.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views2 pages

Python Modules Final Corrected Notes

The document provides an overview of three Python modules: sys, os, and getopt. The sys module is used for handling command-line arguments, the os module allows interaction with the operating system to execute commands, and the getopt module helps parse command-line options and arguments. Examples of usage for each module are included to illustrate their functionalities.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

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='])

You might also like