String formatting with two dictionaries?
Wolfgang Grafen
wolfgang.grafen at marconi.com
Mon Oct 8 05:09:15 EDT 2001
Carsten Gaebler wrote:
>
> Hi there!
>
> Given a string
>
> s = "%(foo)s %(spam)s"
>
> and two dictionaries
>
> d1 = {"foo": "bar"}
> d2 = {"spam": "eggs"}
>
> how would you apply d1 and d2 to s without modifying or explicitly
> copying one of the dicts? I mean, I don't like to
>
> d3 = dictionary(d1)
> d3.update(d2)
> s = s % d3
>
> cg.
foo = d1["foo"]
spam = d2["spam"]
s = s % vars()
:) wolfgang
More information about the Python-list
mailing list