Is it possible to do partial string formatting with the advanced string formatting methods, similar to the string template safe_substitute()
function?
F
If you define your own Formatter
which overrides the get_value
method, you could use that to map undefined field names to whatever you wanted:
http://docs.python.org/library/string.html#string.Formatter.get_value
For instance, you could map bar
to "{bar}"
if bar
isn't in the kwargs.
However, that requires using the format()
method of your Formatter object, not the string's format()
method.