Python OS Module

The os module in Python provides functions for interacting with the operating system. This module helps you with tasks such as file and directory manipulation, environment variables, and process management.

Common Functions in the os Module

Examples

1. Current Working Directory


import os
# Example: Getting the current working directory
print(os.getcwd())  
            

Output

/path/to/current/directory

2. Directory Listing


import os
# Example: Listing files in a directory
print(os.listdir('.'))  
            

Output

['file1.txt', 'file2.py', 'folder1']

The os module in Python allows easy interaction with the operating system, making it a powerful tool for file management, environment handling, and system-related tasks.