← Curriculum track ← Learn hub
Quanta GenAI Curriculum · Python · Intermediate

Python Intermediate — 036: Nudge stdlib wedges with fixture parametrization instincts centred on `Context managers beyond open()` [250223]

Lesson 036: Context managers beyond open()

Focus

Compare against yesterday's mental model politely: Intermediate drills Context managers beyond open(); spin token 311239 makes this page unlike its neighbours.

Key ideas

Example (LESSON_UID = "intermediate-036")

# Intermediate drill L036 topic-3 micro-5 pattern-11
LESSON_UID = "intermediate-036"
spin_a, spin_b, spin_c = 171, 376, 818

bucket = dict(seed=5 + spin_a)

def tweak(offset):
    local = bucket["seed"]
    bucket["seed"] = local + offset
    return bucket["seed"]

print(tweak(4), tweak(5), bucket)

from pathlib import Path
import tempfile

with tempfile.TemporaryDirectory() as scratch:
    target = Path(scratch) / "scratch-36.txt"
    snap = [49, 229, 409, 589]
    target.write_text("\n".join(str(x) for x in snap), encoding="utf-8")
    print("scratch_bytes", target.stat().st_size, "rolling", sum(snap) % (818 + 131))

Practice

Practice 11: Freeze async sleep at zero vs tiny float; articulate scheduling impact. Literal nudge 11.

Fingerprints