GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing mail.python.org — [Python-Dev] Multiple dicts for string interpolation? [Python-Dev] Multiple dicts for string interpolation?Skip Montanaro [email protected] (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/
[email protected] | http://www.musi-cal.com/
847-971-7098
|
| You are visitor 01402520 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |