diff --git a/Doc/library/string.rst b/Doc/library/string.rst --- a/Doc/library/string.rst +++ b/Doc/library/string.rst @@ -683,30 +683,32 @@ these rules. The methods of :class:`Tem :class:`Template` instances also provide one public data attribute: .. attribute:: template This is the object passed to the constructor's *template* argument. In general, you shouldn't change it, but read-only access is not enforced. -Here is an example of how to use a Template: +Here is an example of how to use a Template:: >>> from string import Template >>> s = Template('$who likes $what') >>> s.substitute(who='tim', what='kung pao') 'tim likes kung pao' >>> d = dict(who='tim') - >>> Template('Give $who $100').substitute(d) + >>> Template('Give $who $100').substitute(d) # traceback shortened Traceback (most recent call last): - [...] + File "/usr/local/lib/python3.4/string.py", line 95, in _invalid + (lineno, colno)) ValueError: Invalid placeholder in string: line 1, col 11 - >>> Template('$who likes $what').substitute(d) + >>> Template('$who likes $what').substitute(d) # traceback shortened Traceback (most recent call last): - [...] + File "/usr/local/lib/python3.4/string.py", line 111, in convert + val = mapping[named] KeyError: 'what' >>> Template('$who likes $what').safe_substitute(d) 'tim likes $what' Advanced usage: you can derive subclasses of :class:`Template` to customize the placeholder syntax, delimiter character, or the entire regular expression used to parse template strings. To do this, you can override these class attributes: