Python Tutorials
Standalone Python tutorials built around concrete bugs, performance traps, and everyday scripting tasks. Jump straight to guides on fixing ModuleNotFoundError, avoiding mutable default arguments, reading 10 GB logs line by line, auditing rejected CSV rows, and batching requests with asyncio.gather.
Each tutorial opens with a minimal script and its exact stdout or traceback output, followed by the fix and common mistakes to avoid.
glob() searches one folder, rglob() searches every folder below it. Neither sorts the results, skips folders like .venv, or matches .CSV on Linux.
pip freeze gives exact versions but hides what you chose. A hand-written file shows what you chose but isn't exact.
Separate zero collected tests from an import failure, install into the correct environment, and prove the selected test catches a broken assertion.
for line in file reads one line at a time, so a 10 GB file uses almost no memory. read() and readlines() load everything.
Downloads spend most of their time waiting. ThreadPoolExecutor lets many waits overlap: 20 half-second downloads in 2 seconds instead of 10.
Python refuses to guess whether "5" + 5 means 55 or 10.
People type the wrong thing, sometimes more than once.
Write a context manager when something must be undone no matter how the block ends.