Professional Documents
Culture Documents
Use Standard Libraries Like Os, Itertools, Copy, Math, Re, Requests
Use Standard Libraries Like Os, Itertools, Copy, Math, Re, Requests
Experiment No. 7
Aim: Use Standard libraries like os, itertools, copy, math, re, requests.
OS:
● The OS module in Python provides functions for interacting with the operating system.
● OS comes under Python’s standard utility modules.
● This module provides a portable way of using operating system-dependent functionality.
● To work with the OS module, we need to import the OS module.
o import os
Sr. Function
Purpose Example
No. Name
import os
cwd = os.getcwd()
PS D:/SPP
os.chdir('../')
CST317: Software Proficiency Program-I
NAME : FARHAN PATEL
ROLL.NO : 43
BATCH : A3
print(os.getcwd())
o/p:
PS D:\SPP
import os
directory = 'SGU'
parent_dir = "D:/SGU"
os.mkdir(path)
o/p:
Directory created
os.makedirs(path)
print('Directory created')
CST317: Software Proficiency Program-I
NAME : FARHAN PATEL
ROLL.NO : 43
BATCH : A3
o/p:
Directory created
import os
path = 'D:/SGU'
dir_list = os.listdir(path)
PS D:\SPP>
location = "D:/SGU"
# Path
CST317: Software Proficiency Program-I
NAME : FARHAN PATEL
ROLL.NO : 43
BATCH : A3
os.remove(path)
PS D:\SPP>
import os
directory = "SGU"
# Parent Directory
os.rmdir(path)
PS D:\SPP>
import os
PS D:\SPP>
import os
PS D:\SPP>
import os
we can remove a file in our system
os.remove("C:/SGU/file 2.txt")
using the remove() method. To
os.remove remove a file we need to pass the o/p
11
() name of the file as a parameter. If you
try to remove a file that does not exist
you will get FileNotFoudError.
PS D:\SPP>
import os
print(result)
This method will check whether a file
os.path.exi
12 exists or not by passing the name of o/p
sts()
the file as a parameter
False
PS D:\SPP>
parameter.
o/p
PS D:\SPP>