System Module and OS Module
Its Important Functionalities
Dear Readers,
Today I would like to share major functionalities from OS and SYS module,
Function of OS module is that it allows the user(you) to interact with the operating system of your device:
1.os.name
==>This helps to get the information on current operating system of your device
1 2 | >>> os.name 'nt' |
2.os.getcwd()
==>This Function os.getcwd(), returns the Current Working Directory(CWD) of the file used to execute the code, can vary from system to system.
1 2 | >>> os.getcwd() 'C:\\Users\\Example\\OneDrive\\Desktop\\python playlist' |
3. os.rename('existing_file_name','new_file_name')
==> This function is used to change the name of the file. The name of the file changes only if, the file exists and user has sufficient privilege permission to change the file.
1. sys.argv
==>This function returns a list of command line arguments passed to python script. The name of the script is always the item at index 0,and the rest of the arguments are stored at subsequent indices.
1 2 | >>> sys.argv[0] 'C:\\Users\\Adarsh tiwari\\OneDrive\\Desktop\\python playlist\\test.py' |
2. sys.exit
==>This causes the script to exit to either python console or the command prompt. This is a way of safe exit in case of generation of error
3.sys.path
==>This modules search paths can be identified using this function
1 2 | >>> sys.path ['C:\\Users\\Adarsh tiwari\\OneDrive\\Desktop\\python playlist', 'C:\\Users\\Adarsh tiwari\\AppData\\Local\\Programs\\Python\\Python39\\python39.zip', 'C:\\Users\\Adarsh tiwari\\AppData\\Local\\Programs\\Python\\Python39\\DLLs', 'C:\\Users\\Adarsh tiwari\\AppData\\Local\\Programs\\Python\\Python39\\lib', 'C:\\Users\\Adarsh tiwari\\AppData\\Local\\Programs\\Python\\Python39', 'C:\\Users\\Adarsh tiwari\\AppData\\Local\\Programs\\Python\\Python39\\lib\\site-packages'] |
4.sys.maxsize
==>This module returns the largest value an integer can take
1 2 | >>> sys.maxsize 9223372036854775807 |