String formatting with two dictionaries?

Carsten Gaebler clpy at snakefarm.org
Mon Oct 8 04:42:28 EDT 2001


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.



More information about the Python-list mailing list