Skip to Content
Skip to content
PROGRAMMING

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.

Python
Finding Files in Python With pathlib glob and rglob Level: Intermediate

glob() searches one folder, rglob() searches every folder below it. Neither sorts the results, skips folders like .venv, or matches .CSV on Linux.

Python
pip freeze vs Writing requirements.txt by Hand: Which One to Use Level: Intermediate

pip freeze gives exact versions but hides what you chose. A hand-written file shows what you chose but isn't exact.

Python
Diagnose pytest Discovery and src-Layout Import Errors Level: Intermediate

Separate zero collected tests from an import failure, install into the correct environment, and prove the selected test catches a broken assertion.

Python
Reading a Large Text File in Python Line by Line Level: Intermediate

for line in file reads one line at a time, so a 10 GB file uses almost no memory. read() and readlines() load everything.

Python
Speeding Up Many Downloads in Python With ThreadPoolExecutor Level: Advanced

Downloads spend most of their time waiting. ThreadPoolExecutor lets many waits overlap: 20 half-second downloads in 2 seconds instead of 10.

Python
Python Type Conversion: Why "5" + 5 Fails and How to Fix It Level: Beginner

Python refuses to guess whether "5" + 5 means 55 or 10.

Python
Writing Your Own Python Context Manager, With a Class or contextlib Level: Advanced

Write a context manager when something must be undone no matter how the block ends.