Printing formatted strings from a dictionary
Terry Reedy
tjreedy at udel.edu
Fri May 21 14:23:58 EDT 2004
"Peter Abel" <PeterAbel at gmx.net> wrote in message
news:21064255.0405201224.77a7574f at posting.google.com...
> >>> d={'1':2} # Remark the quotmarks '1'
> >>> '%(1)i'%d
> '2'
> I even would not have believed that this kind of formatting would work.
> But the more I think about it the more it becomes consequential and
logical.
>From Lib Ref 2.3.6.2. String Formatting ...
Mapping key (optional), consisting of a parenthesised sequence of
characters (for example, somename)).
Examples generally use names for the char sequence, but restricting the
sequence to a name would require more work for less functionality. Since %
works with unicode as well as byte strings, one can, I presume, interpolate
with unicode keys as well.
Terry J. Reedy
More information about the Python-list
mailing list