utility
0
Q:

python os

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
# Python program to explain os.getcwd() method  
        
# importing os module  
import os  
    
# Get the current working  
# directory (CWD)  
cwd = os.getcwd()  
    
# Print the current working   
# directory (CWD)  
print("Current working directory:", cwd)  
1
#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
import os 
fd = "GFG.txt"
os.rename(fd,'New.txt') 
os.rename(fd,'New.txt')
-2
try:
    fp = open("myfile")
except PermissionError:
    return "some default data"
else:
    with fp:
        return fp.read()
-4

New to Communities?

Join the community