The os
module is a built-in module in Python that provides a way to interact with the operating system. It contains functions for interacting with the file system, process management, environment variables, and other system-specific functionalities.
Here are some of the main functions provided by the os
module:
os.getcwd()
– Returns the current working directory of the process.os.chdir(path)
– Changes the current working directory to the specified path.os.listdir(path='.')
– Returns a list of files and directories in the specified directory.os.mkdir(path)
– Creates a new directory at the specified path.os.rmdir(path)
– Removes the directory at the specified path (only works if the directory is empty).os.rename(src, dst)
– Renames a file or directory from the source path to the destination path.os.remove(path)
– Deletes the file at the specified path.os.path.join(path1[, path2[, ...]])
– Joins two or more path components together.os.path.abspath(path)
– Returns the absolute path of the specified path.os.path.exists(path)
– Returns True if the specified path exists, False otherwise.os.path.isfile(path)
– Returns True if the specified path is a file, False otherwise.os.path.isdir(path)
– Returns True if the specified path is a directory, False otherwise.os.environ
– A dictionary-like object containing the environment variables.os.system(command)
– Executes the specified command in a subshell.
These are just a few examples of the functions provided by the os
module. The module is quite powerful and allows you to perform many different types of operations on the operating system from within Python.