[Python-checkins] r86263 - python/branches/py3k/Doc/library/stdtypes.rst

eric.smith python-checkins at python.org
Sat Nov 6 14:22:13 CET 2010


Author: eric.smith
Date: Sat Nov  6 14:22:13 2010
New Revision: 86263

Log:
Added example for str.format_map().

Modified:
   python/branches/py3k/Doc/library/stdtypes.rst

Modified: python/branches/py3k/Doc/library/stdtypes.rst
==============================================================================
--- python/branches/py3k/Doc/library/stdtypes.rst	(original)
+++ python/branches/py3k/Doc/library/stdtypes.rst	Sat Nov  6 14:22:13 2010
@@ -1042,9 +1042,17 @@
 
    Similar to ``str.format(**mapping)``, except that ``mapping`` is
    used directly and not copied to a :class:`dict` .  This is useful
-   if for example ``mapping`` is a dict subclass.
+   if for example ``mapping`` is a dict subclass:
+
+   >>> class Default(dict):
+   ...     def __missing__(self, key):
+   ...         return key
+   ...
+   >>> '{name} was born in {country}'.format_map(Default(name='Guido'))
+   'Guido was born in country'
+
+   .. versionadded:: 3.2
 
-    .. versionadded:: 3.2
 
 .. method:: str.index(sub[, start[, end]])
 


More information about the Python-checkins mailing list