OS module in python
1 min readJan 21, 2023
The os
library in Python provides a way for developers to interact with the operating system. This library contains a wide variety of functionality, including the ability to interact with the file system, execute shell commands, and interact with environment variables. Some of the most commonly used functions in the os
library include:
os.path
: This module contains a variety of functions for working with file paths, includingos.path.join()
joining paths together,os.path.exists()
checking if a file or directory exists,os.path.isdir()
andos.path.isfile()
for checking if a path is a directory or file, respectively.os.listdir()
: This function returns a list of all files and directories in a given directory.os.mkdir()
: This function creates a new directory.os.rmdir()
: This function deletes an empty directory.os.remove()
: This function deletes a file.os.rename()
: This function renames a file or directory.os.system()
: This function allows you to execute a shell command.os.environ
: This is a dictionary-like object containing key-value pairs for all environment variables.os.getcwd()
: This function returns the current working directory.os.chdir()
: This function changes the current working directory.os.getpid()
: This function returns the current process id.
Thank you for reading !!!
If you enjoy this article and would like to Buy Me a Coffee, please click here.
you can connect with me on Linkedin.