Standard-library data boundaries
The standard library handles common formats without a dependency install. json decodes structured text into Python values and encodes values back into text. datetime understands calendar rules that string slicing cannot validate. pathlib separates path operations from handwritten separator handling, and temporary files let you practice real reads and writes inside the runtime's virtual file system. Choose the module that owns the format, then make the input and output rules explicit. You'll create deterministic JSON, calculate calendar dates, inspect path components, and round-trip a small text file. Paths supplied for inspection are treated as data. The file exercise chooses its own temporary location and never accesses a host path.
import json
def canonical_config(payload, increment):
values = json.loads(payload)
updated = {key: value + increment for key, value in values.items()}
return json.dumps(updated, sort_keys=True, separators=(",", ":"))
date.fromisoformat('2028-02-28') + timedelta(days=1) is February 29 because 2028 is a leap year. A fixed list of month lengths would need to reproduce that calendar logic.