os - Operating System Interface
The os module provides a portable way of using operating system dependent functionality. It includes functions for file and directory operations, process management, and environment variables.
🔍 Key Areas
File and Directory Operations
os.listdir()- List directory contentsos.makedirs()- Create directories recursivelyos.remove()- Remove filesos.rmdir()- Remove directories
Path Operations
os.path.join()- Join path componentsos.path.exists()- Check if path existsos.path.abspath()- Get absolute pathos.path.dirname()- Get directory name
Process and Environment
os.environ- Environment variablesos.getpid()- Get process IDos.system()- Execute system commands
💡 Migration Note
For new code, consider using:
pathlibinstead ofos.pathfor path operationssubprocessinstead ofos.system()for running commandsshutilfor high-level file operations