I need to format a command line where some parameters come from simple variables, and others are the result of a longer expression. Python f-strings work well for the variables, and I'm using a printf-style %s and providing the long expression outside the string because it would just clutter the command template too much if placed inline:
run(f"""zstd -dc {diff_file} |
git apply -p2 {exclude_args} --directory='%s'""" % (os.getcwd() + "/output"))
I didn't store the directory parameter in a named variable because it only gets used once as opposed to diff_file and exclude_args.
Is there a cleaner way to avoid putting os.getcwd() + "/output" directly in the f-string, and also avoid mixing old printf %s syntax and new f-strings ?
Are there downsides to doing it like above other than it being a bit confusing to someone who reads the code ?
Edit: to clarify, my question is how to put placeholders in f-strings without declaring additional named variables, not how to inline calls to getcwd() in f-strings.
{os.getcwd()}"output"by itself?run(f"git apply -d '{(os.getcwd()}/output}' -p2").