No love for Python's shlex.quote[1] or their equivalents in other languages to quote arguments for shell? In his case, which is interpolating a variable inside a shell double-quoted string, I would probably use environment variables, or else use shell `printf` with `shlex.quote`. But generally I interpolate directly into the command line using `shlex.quote`, when I can't avoid executing using the shell.
I was happy to learn about Python's template string proposal (i.e., t-strings) from https://peps.python.org/pep-0750/, although it probably won't become common for a while.
[1] https://docs.python.org/3/library/shlex.html#shlex.quote