Table of Contents

import os

import os is a Python import that provides functions for interacting with the operating system: file paths, environment variables, process information, and filesystem operations. Use this for cross-platform file handling, reading environment, and running system commands.

Example

# Python
# description: list files in current directory, get home path
 
import os
 
# Print current working directory
print(os.getcwd())
 
# List files in directory
for name in os.listdir('.'):
    print(name)
 
# Access environment variables
home = os.environ.get('HOME')
print(f"Home: {home}")
 
# Get process ID
print(f"Process ID: {os.getpid()}")

Common functions