Next / Previous / Contents / TCC Help System / NM Tech homepage

7.2.3. String formatting from a dictionary

You can use the string format operator % to format a set of values from a dictionary D (see Section 9, “Type dict: Dictionaries”):

f % D

In this form, the general form for a format code is:

%(k)[p][m[.n]]c

where k is a key in dictionary D, and the rest of the format code is as in the usual string format operator. For each format code, the value of D[k] is used. Example:

>>> named = {'last': 'Poe', 'first': 'Aloysius'}
>>> 'Dear %(first)s %(last)s:' % named
'Dear Aloysius Poe:'