# Exact one-occurrence replacements: rep.py FILE (pairs read from a Python list in PAIRS env file) import sys from pathlib import Path def rep(p, old, new): f = Path(p); s = f.read_text() n = s.count(old) if n != 1: sys.exit(f"{p}: {n} matches for {old[:60]!r}") f.write_text(s.replace(old, new))