Skip to Content
0 likes
Fix pip Installing Into the Wrong Python Environment Level: Intermediate

Reproduce an interpreter mismatch, compare executable, pip and module paths, then verify the repair from the Python environment that runs the application.

0 likes
Audit Rejected CSV Rows and Reconcile Every Input Record Level: Intermediate

Validate a defined spreadsheet-export contract, record rejected rows with reasons and line ranges, and reconcile accepted and rejected outputs without changing the source.

0 likes
Python Dictionary Comprehensions: When They Help and When They Hurt Level: Intermediate

A dictionary comprehension builds a dictionary in one line. Good for transforming, filtering and building lookups. Bad for nested logic, side effects and anything that needs error handling. Shorter code is not always better code.

0 likes
Python dataclasses: A Class Without Writing __init__ by Hand Level: Intermediate

If a class mostly holds data, @dataclass writes __init__, a readable printout and equality for you. Use field(default_factory=list) for lists, __post_init__ for checks and frozen=True for values that must not change.

0 likes
Fixing ModuleNotFoundError in Python, One Cause at a Time Level: Intermediate

ModuleNotFoundError has a handful of causes: the wrong Python, an inactive virtual environment, the wrong folder, or a file that shadows a module. Check them in order instead of reinstalling.

0 likes
Python if __name__ == "__main__": What It Does and When You Need It Level: Intermediate

Importing a file runs it. if __name__ == "__main__" keeps a file's script part from running when another file imports it. Use it with a main() function, and know the cases where you don't need it.

0 likes
Python logging: Replacing print() Before It Gets Out of Hand Level: Intermediate

print() is for the output a person asked for. logging is for messages about the program: levels you can turn down, a file with times, and tracebacks for errors. Set it up once in main() and use a logger per module.

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.