diff options
author | Eric Smith <eric@trueblade.com> | 2011-01-28 20:23:25 (GMT) |
---|---|---|
committer | Eric Smith <eric@trueblade.com> | 2011-01-28 20:23:25 (GMT) |
commit | 598b513a5deae1add8fc877694890bb6e1c44b49 (patch) | |
tree | 7eebfe0ae269b955b63c35a4d37eab1bd9df48ca /Doc/whatsnew | |
parent | e180d3953f24330f1f5c3475ca4f46331a62312b (diff) | |
download | cpython-598b513a5deae1add8fc877694890bb6e1c44b49.zip cpython-598b513a5deae1add8fc877694890bb6e1c44b49.tar.gz cpython-598b513a5deae1add8fc877694890bb6e1c44b49.tar.bz2 |
Added a placeholder for str.format_map, as discussed with Raymond. My prose is horrible, some cleanup is required.
Diffstat (limited to 'Doc/whatsnew')
-rw-r--r-- | Doc/whatsnew/3.2.rst | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/Doc/whatsnew/3.2.rst b/Doc/whatsnew/3.2.rst index 94257ae..ea41f88 100644 --- a/Doc/whatsnew/3.2.rst +++ b/Doc/whatsnew/3.2.rst @@ -442,6 +442,26 @@ Some smaller changes made to the core Python language are: (Suggested by Mark Dickinson and implemented by Eric Smith in :issue:`7094`.) +.. XXX * :meth:`str.format_map` was added, allowing an arbitrary mapping object + to be passed in to :meth:`str.format`. `somestring.format_map(mapping)` + is similar to `somestring.format(**mapping)`, except that in the latter + case `mapping` is convert to a `dict` and in the former case `mapping` + is used without modification. For example, to use a `defaultdict` with + formatting:: + + >>> from collections import defaultdict + >>> mapping = defaultdict(lambda: 'Europe', name='Guido') + >>> '{name} was born in {country}'.format_map(mapping) + 'Guido was born in Europe' + + This is similar to %-formatting with a single mapping argument:: + + >>> '%(name)s was born in %(country)s' % mapping + 'Guido was born in Europe' + + (Suggested by Raymond Hettinger and implemented by Eric Smith in + :issue:`6081`.) + * The interpreter can now be started with a quiet option, ``-q``, to suppress the copyright and version information from being displayed in the interactive mode. The option can be introspected using the :attr:`sys.flags` attribute:: |