File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -442,6 +442,26 @@ Some smaller changes made to the core Python language are:
442442
443443 (Suggested by Mark Dickinson and implemented by Eric Smith in :issue: `7094 `.)
444444
445+ .. XXX * :meth:`str.format_map` was added, allowing an arbitrary mapping object
446+ to be passed in to :meth:`str.format`. `somestring.format_map(mapping)`
447+ is similar to `somestring.format(**mapping)`, except that in the latter
448+ case `mapping` is convert to a `dict` and in the former case `mapping`
449+ is used without modification. For example, to use a `defaultdict` with
450+ formatting::
451+
452+ >>> from collections import defaultdict
453+ >>> mapping = defaultdict(lambda: 'Europe', name='Guido')
454+ >>> '{name} was born in {country}'.format_map(mapping)
455+ 'Guido was born in Europe'
456+
457+ This is similar to %-formatting with a single mapping argument::
458+
459+ >>> '%(name)s was born in %(country)s' % mapping
460+ 'Guido was born in Europe'
461+
462+ (Suggested by Raymond Hettinger and implemented by Eric Smith in
463+ :issue:`6081`.)
464+
445465 * The interpreter can now be started with a quiet option, ``-q ``, to suppress
446466 the copyright and version information from being displayed in the interactive
447467 mode. The option can be introspected using the :attr: `sys.flags ` attribute::
You can’t perform that action at this time.
0 commit comments