I’m using ConfigObj in python with Template-style interpolation. Unwrapping my config dictionary via ** doesn’t seem to do interpolation. Is this a feature or a bug? Any nice workarounds?
$ cat my.conf
foo = /test
bar = $foo/directory
>>> import configobj
>>> config = configobj.ConfigObj('my.conf', interpolation='Template')
>>> config['bar']
'/test/directory'
>>> '{bar}'.format(**config)
'$foo/directory'
I’d expect the second line to be /test/directory. Why doesn’t interpolation work with **kwargs?
When unpacking the keyword argument, then a new object is created: of type
dict. This dictionary contains the the raw-values of the configuration (no interpolation)Demonstration:
To resolve your problem you could create an expanded version of your configuration like this:
Another more elegant way is to simply avoid unpacking: This can be achieved by using the function string.Formatter.vformat: