[Python-Dev] Multiple dicts for string interpolation?
Skip Montanaro
skip@mojam.com (Skip Montanaro)
Tue, 25 Jan 2000 21:42:06 -0600
Every once in awhile I want to perform string interpolation using more than
one dictionary. One way is to build a dictionary that's a union of multiple
dictionaries:
dict = {}
dict.update(d1)
dict.update(d2)
...
s = format % dict
Another way is the MultiDict approach that Digital Creations (used to?) use
in their DocumentTemplate module (I can't remember the exact usage any
more):
dict = MultiDict()
dict.append(d1)
dict.append(d2)
...
s = format % dict
A MultiDict object maintains a list of the dicts it's been fed and searches
them in order when __getitem__ is called.
I'd like to propose a third alternative. How about if the string
interpolation function accepted a tuple of dictionaries directly:
s = format % (d1, d2)
It would only be used when named interpolation was expected. I don't think
there would be any conflict with current % operator semantics.
Skip Montanaro | http://www.mojam.com/
skip@mojam.com | http://www.musi-cal.com/
847-971-7098