Skip to Content
0 likes
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. Add those yourself, and always do a dry run before deleting anything.

0 likes
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. For anything you deploy, keep both: one file for intent, one frozen for exact versions.

0 likes
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.

0 likes
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. Count, filter and stop early without building a list, and read in blocks when there are no lines.

0 likes
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. Handle failures with as_completed, pick a sensible worker count and respect the server.

0 likes
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. Convert with int(), float() and str() where values come in, handle text that won't convert, and avoid the bool("False") trap.

0 likes
Python while Loops: Keep Asking Until the Input Is Valid Level: Beginner

People type the wrong thing, sometimes more than once. A while True loop with try/except, a range check and a way out keeps asking until the answer is usable, so the rest of your code never has to check again.

0 likes
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. Build one as a class and with @contextmanager, keep yield inside try/finally, and don't swallow errors by accident.