When unpacking the keyword argument, a new object is created: of type dict . This dictionary contains the original configuration values ββ(no interpolation)
Demonstration:
>>> id(config) 31143152 >>> def showKeywordArgs(**kwargs): ... print(kwargs, type(kwargs), id(kwargs)) ... >>> showKeywordArgs(**config) ({'foo': '/test', 'bar': '$foo/directory'}, <type 'dict'>, 35738944)
To solve your problem, you can create an advanced version of your configuration as follows:
>>> expandedConfig = {k: config[k] for k in config} >>> '{bar}'.format(**expandedConfig) '/test/directory'
Another elegant way is simply to avoid unpacking: this can be achieved using the string.Formatter.vformat function:
import string fmt = string.Formatter() fmt.vformat("{bar}", None, config)
gecco
source share