I want to create an f-string that combines two strings, prepending a '.' character to the second if it is not empty.
reference = "file"
modifier = "read"
print(f"unknown pattern") # Should output "file.read" since modifier is not empty
modifier = ""
print(f"unknown modifier") # Should output "file" (not "file.") since modifier is empty
Is there a dedicated syntax for this kind of conditional prefixing, similar to that used in twig?
I would like to avoid using str.join() or conditional statements if possible.
.rstrip(".")to your f-string. Unless yourmodifierorreferenceends with a dot... but that might not be your case?'.'.join(s for s in (reference, modifier) if s)?