A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2000-January/001871.html below:

[Python-Dev] Multiple dicts for string interpolation?

[Python-Dev] Multiple dicts for string interpolation?Tim Peters tim_one@email.msn.com
Wed, 26 Jan 2000 00:39:19 -0500
[Skip, wants to interpolate multiple dicts via "%",
 suggests passing a tuple of dicts:  format % (d1, d2, ...)]

[Guido]
> ...
> I think it depends on to what extent this is a common, useful
> idiom.  Do you have evidence of that?  Examples?

You yourself raised one last century <wink>:  simply wanting to interpolate
from both locals() and globals().  At the time, the idea of a new dict-like
mapping object (capturing Python's lookup rules) appealed to you.  I still
like that, and note that the apparent need becomes more acute if "deep
nesting" is ever added.

I wasn't aware of the MultiDict approach Skip mentioned, but thought it
looked spot on for the general case!  Skip, is the long-windedness of

    dict = MultiDict()
    dict.append(d1)
    dict.append(d2)
    ...
    s = format % dict

the part you didn't like about that?  If so, how about changing the
constructor to

    def __init__(self, *dicts):
         ...

instead so you could use it as a one-liner

    format % MultiDict(d1, d2, ...)

?  That's exactly the same as the tuple idea, except there's a nice
descriptive word in the middle of it <wink>.





RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4