Lesson 049: Exceptions: catching, chaining, guarding
Focus
Assume a reviewer executes this verbatim: Intermediate drills Exceptions: catching, chaining, guarding; spin token 443443 makes this page unlike its neighbours.
Key ideas
- Angle
Intermediate: micro cadence9mixesExceptions: catching, chaining, guarding; spin27687. - Ritual: Add one doctest-style assertion comment above hottest print.
- Guardrail: promise one security boundary if this touched user data.
Example (LESSON_UID = "intermediate-049")
# Intermediate drill L049 topic-4 micro-8 pattern-12
LESSON_UID = "intermediate-049"
spin_a, spin_b, spin_c = 978, 974, 337
from io import StringIO
buf = StringIO()
rounds = 3 + 8 % 5
for idx in range(rounds):
buf.write(f"seg-{idx}-{(idx * 49 + spin_b) % 997}\n")
buf.seek(0)
dump = buf.read()
print("lines", dump.count("\n"))
print("peek", dump.splitlines()[0] if dump else "<empty>")
from pathlib import Path
import tempfile
with tempfile.TemporaryDirectory() as scratch:
target = Path(scratch) / "scratch-49.txt"
snap = [62, 61, 60]
target.write_text("\n".join(str(x) for x in snap), encoding="utf-8")
print("scratch_bytes", target.stat().st_size, "rolling", sum(snap) % (337 + 131))
Practice
Practice 9: Shadow one variable purposely to spotlight scope quirks. Literal nudge 9.
Fingerprints
- lesson_uid:
intermediate-049 - umbrella band:
Exceptions: catching, chaining, guarding(9/10) - lesson_index:
1593