String formatting with two dictionaries?

Chris Liechti cliechti at gmx.net
Mon Oct 8 13:54:39 EDT 2001


Carsten Gaebler <clpy at snakefarm.org> wrote in 
news:3BC166F4.5E7FAB08 at snakefarm.org:
> 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? > 

s = ("%(foo)s %%(spam)s" % d1) % d2

use two "%" for variables that are in the second dict.

Chris

-- 
Chris <cliechti at gmx.net>




More information about the Python-list mailing list