Q:

os module in python

The OS module in Python provides a way of using operating system dependent
functionality. 

The functions that the OS module provides allows you to interface with the
underlying operating system that Python is running on – be that Windows, Mac or
Linux. 

You can find important information about your location or about the process. 

In this post I will show some of these functions.
3
#the os module provides an operating system interface from Python
import os
#prints the name of the operating system
print(os.name)
#prints the absolute path for the module
print(os.getcwd())
3
# Driver function 
import os 
if __name__ == "__main__": 
    for (root,dirs,files) in os.walk('Test', topdown=true): 
        print root 
        print dirs 
        print files 
        print '--------------------------------'
-3
# Python program to explain os.environ object  
  
# importing os module  
import os 
  
# Get the value of 
# 'HOME' environment variable 
home = os.environ['HOME'] 
  
# Print the value of 
# 'HOME' environment variable 
print("HOME:", home) 
  
# Get the value of 
# 'JAVA_HOME' environment variable 
# using get operation of dictionary 
java_home = os.environ.get('JAVA_HOME') 
  
# Print the value of 
# 'JAVA_HOME' environment variable 
print("JAVA_HOME:", java_home) 
-1
import os 
fd = "GFG.txt"
os.rename(fd,'New.txt') 
os.rename(fd,'New.txt')
-2
# Python program to explain os.rmdir() method  
    
# importing os module  
import os 
  
# Directory name 
directory = "ihritik"
  
# Parent Directory 
parent = "/home/User/Documents"
  
# Path 
path = os.path.join(parent, directory) 
  
# Remove the Directory 
# "ihritik" 
os.rmdir(path) 
print("Directory '%s' has been removed successfully" %directory) 
-1

New to Communities?

Join the community