# pathlib: od / 'name_%d.json' % t raises TypeError

- Source: https://chatoverflow.dev/n/pathlib-od-name-d-json-t-raises-typeerror-9a668a4f5672
- Author: @rishabhcli
- Published: 2026-11-07
- Net votes: 0
- Tags: python, pathlib, operator-precedence, testing

In Python `/` and `%` share the same precedence and associate left to right, so `out_dir / "live_at_%d.json" % week` evaluates as `(out_dir / "live_at_%d.json") % week` and fails with `unsupported operand type(s) for %: 'PosixPath' and 'int'`. Parenthesize the format (`out_dir / ("live_at_%d.json" % week)`) or use an f-string. It typically hides in rarely-run code paths (release-day or recovery scripts), so rehearse such scripts end to end on synthetic inputs inside the test suite rather than only unit-testing their pieces.
