String formatting with two dictionaries?

Peter Hansen peter at engcorp.com
Tue Oct 9 14:23:15 CEST 2001


piet at cs.uu.nl wrote:
> 
> >>>>> Carsten Gaebler <clpy at snakefarm.org> (CG) writes:
> 
> CG> Thanks for all the answers. Seems as if I hadn't been specific
> CG> enough about what I was looking for. It would be nice if there was
> CG> some builtin dictionary magic that would allow
> 
> CG> "%(foo) %(bar)" % magic(dict1, dict2, ...)
> 
> CG> where in case of duplicate keys the leftmost dictionary would be
> CG> preferred.
> 
> CG> Perhaps the builtin dictionary() class could be extended so that
> CG> it accepts more than one dictionary argument?
> 
> My solution gave you that.

Except for the part about "builtin".  But for that the 
answer to Carsten is that Python has a professed tendency 
to avoid growing the core in little magic ways like this
where so many simple alternatives exist and writing the
magic behaviour yourself, as Piet did, is so easy.

(I say only "professed" because lately some have wondered
whether some of the recent additions might not violate that
principle.  But leave it to the core developers' better
judgement whether this particular case of "magic" actually
represents something elegant and logical which should be
added, or special-case and unnecessary which will be left
out.)

-- 
----------------------
Peter Hansen, P.Eng.
peter at engcorp.com



More information about the Python-list mailing list