I have a complex nested dict object, for example:
value = { 'a': '100', bits: { 1: 'alpha', 2: 'beta', 3: ['31', '32', 901] } }
I need to "securely" format it using a template. If no keys are found, just silently ignore the {} holders. Keys may be missing, and I do not want to raise KeyErrors. The problem is that string.Template cannot process the same functions as str.format. The str.format used is something like:
"a=${a}, b1={bits[1]}, b31={bits[3]}, b9={bits[9]}".format(**value)
and the conclusion should be:
"a=100, b1=alpha, b31=(31, 32, 901), b9="
I don't need fancy loops or if / else conditions. Just simple formats with subdisks.
What options do I have? I prefer to use the built-in modules as much as possible or a very small library.
This is not a web application, so no, if possible, I want to avoid loading lib like jinja2, just for that.