]> granicus.if.org Git - python/commitdiff
Added example for str.format_map().
authorEric Smith <eric@trueblade.com>
Sat, 6 Nov 2010 13:22:13 +0000 (13:22 +0000)
committerEric Smith <eric@trueblade.com>
Sat, 6 Nov 2010 13:22:13 +0000 (13:22 +0000)
Doc/library/stdtypes.rst

index ebe7b7604c859ebd053f57e5408a4e1380ababfa..0ac870be217595541ac7e1ffdf09dc2925438ea1 100644 (file)
@@ -1042,9 +1042,17 @@ functions based on regular expressions.
 
    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]])