Is it possible to do partial string formatting with the advanced string formatting methods, similar to the string template safe_substitute()
function?
For example:
s = '{foo} {bar}'
s.format(foo='FOO') #Problem: raises KeyError 'bar'
pythonstring-formatting
Is it possible to do partial string formatting with the advanced string formatting methods, similar to the string template safe_substitute()
function?
For example:
s = '{foo} {bar}'
s.format(foo='FOO') #Problem: raises KeyError 'bar'
Best Answer
If you know in what order you're formatting things:
Use it like this:
You can't specify
foo
andbar
at the same time - you have to do it sequentially.