I have a string that I'd like to format but the values I'm using to format may or may not be proper values (None, or ''). In any event that one of these improper values is passed, I still want the string to format, but ignoring any values that will not work. For example:
mystring = "{:02d}:{:02d}"
mystring.format('', 1)
In this case I'd like my output to be :01, thus negating the fact that '' won't work for the first value in the string. I looked at something like
class Default(dict):
def __missing__(self, key):
return key.join("{}")
d = Default({"foo": "name"})
print("My {foo} is {bar}".format_map(d)) # "My name is {bar}"
But as I'm not using a dictionary for values, I don't think this solution will work for me.