Lesson 035: Context managers beyond open()
Focus
Treat the excerpt as executable notes: Intermediate drills Context managers beyond open(); spin token 318270 makes this page unlike its neighbours.
Key ideas
- Angle
Intermediate: micro cadence5mixesContext managers beyond open(); spin12876. - Ritual: Swap one benign literal twice to see binding effects.
- Guardrail: pick the budget that keeps this rehearsal honest.
Example (LESSON_UID = "intermediate-035")
# Intermediate drill L035 topic-3 micro-4 pattern-12
LESSON_UID = "intermediate-035"
spin_a, spin_b, spin_c = 635, 594, 376
from io import StringIO
buf = StringIO()
rounds = 3 + 4 % 5
for idx in range(rounds):
buf.write(f"seg-{idx}-{(idx * 35 + 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-35.txt"
snap = [48, 691, 343]
target.write_text("\n".join(str(x) for x in snap), encoding="utf-8")
print("scratch_bytes", target.stat().st_size, "rolling", sum(snap) % (376 + 131))
Practice
Practice 34: Clone twice: expand literals vs shrink loops; compare narrative. Literal nudge 34.
Fingerprints
- lesson_uid:
intermediate-035 - umbrella band:
Context managers beyond open()(5/10) - lesson_index:
1117