Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 598b513

Browse files
committed
Added a placeholder for str.format_map, as discussed with Raymond. My prose is horrible, some cleanup is required.
1 parent e180d39 commit 598b513

1 file changed

Lines changed: 20 additions & 0 deletions

File tree

Doc/whatsnew/3.2.rst

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff 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::

0 commit comments

Comments
 (0)