So, I'm writing a small backup solution that loads some configuration settings from a YAML file. I would like to allow the user to set a naming scheme for the generated backup. Something like:
{database_name} @ {host} {month}_{year}
And allow them to freely choose fields from a set. The first thing that comes to my mind while thinking about how to convert this to a final string, is using the string's format
method.
The code would then check for every possible field and if it exists, format the string accordingly. I wonder, however if there is a more pythonic way to go about this than just looping through the string, checking for every possible field and replacing the value.