Skip to main content

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 contents
  • os.makedirs() - Create directories recursively
  • os.remove() - Remove files
  • os.rmdir() - Remove directories

Path Operations

  • os.path.join() - Join path components
  • os.path.exists() - Check if path exists
  • os.path.abspath() - Get absolute path
  • os.path.dirname() - Get directory name

Process and Environment

  • os.environ - Environment variables
  • os.getpid() - Get process ID
  • os.system() - Execute system commands

💡 Migration Note

For new code, consider using:

  • pathlib instead of os.path for path operations
  • subprocess instead of os.system() for running commands
  • shutil for high-level file operations