def foo(string, **kwargs):
return string % kwargs # simplified a much more complex SQL query function with argument binding.
string = '%(a)s %(b)s.'
print foo(string %{'a': 'Hello'}, b='world')
I want to achieve this '%(a)s %(b)s' => 'Hello %(b)s' => 'Hello world' (and not '%(a)s %(b)s' => 'Hello world' in one go).
Is there anyway in python to make it work?
%operator is not officially deprecated but newer code is supposed to use the new string format spec mini-language