Tutorials
Practical tutorials for the work we actually do. Pick one, read it in order, and apply it.
Validate a defined spreadsheet-export contract, record rejected rows with reasons and line ranges, and reconcile accepted and rejected outputs without changing the source.
asyncio.gather runs many waiting tasks at once in one thread and returns results in order. Avoid await in a loop and blocking calls, keep failures with return_exceptions=True, and limit concurrency with a Semaphore.
glob() searches one folder, rglob() searches every folder below it. Neither sorts the results, skips folders like .venv, or matches .CSV on Linux. Add those yourself, and always do a dry run before deleting anything.
for line in file reads one line at a time, so a 10 GB file uses almost no memory. read() and readlines() load everything. Count, filter and stop early without building a list, and read in blocks when there are no lines.
Downloads spend most of their time waiting. ThreadPoolExecutor lets many waits overlap: 20 half-second downloads in 2 seconds instead of 10. Handle failures with as_completed, pick a sensible worker count and respect the server.
Read a CSV too big for memory line by line with readline, total a column, and write a filtered copy with pipeline. Memory stays flat no matter how big the file is.