Cheatsheets
Python cheatsheet
venv, modules, virtualenv, and common standard-library calls.
Environment
| Command / topic | What it does |
python3 -m venv .venv | Create a virtual environment |
source .venv/bin/activate | Activate on Linux/macOS |
pip install -r requirements.txt | Install dependencies |
python -m pytest | Run tests as a module |
Language essentials
| Command / topic | What it does |
from pathlib import Path | Preferred path handling |
with open(path) as f: | Safe file open/close |
list(dict.fromkeys(items)) | Deduplicate while preserving order |
{k: v for k, v in d.items() if v} | Dict comprehension filter |
Debugging
| Command / topic | What it does |
python -m pdb script.py | Start the debugger |
raise SystemExit("msg") | Exit with a clear error |
import traceback; traceback.print_exc() | Print a caught stack |
← All cheatsheets · Courses