I'd like to use both parse time and runtime interpolation for values of a configobj configuration file. The easiest way to do simple string interpolation in Python is "%(foo)s" % somedict
. Unfortunately configobj uses the same interpolation mechanism and I have not yet found a way to escape it. Ideally my value would look like:
othervar = foo
someconfigobjkey = %(othervar)s %%(runtimevar)s
However configobj tries (and fails) to replace the second variable. Another way to answer this question is to provide a different (configobj) way to do both parse time and runtime interpolation.
Digging deeper in the documentation I found a solution that fits better than the one proposed by bobince: Use a different interpolation engine, such as interpolation="template"
. It has two advantages.
$$
gets interpolated to $
.)The example would look like:
othervar = foo
someconfigobjkey = $othervar %(runtimevar)s
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With