[issue13173] Default values for string.Template
Raymond Hettinger
report at bugs.python.org
Wed Oct 19 01:41:56 CEST 2011
Raymond Hettinger <raymond.hettinger at gmail.com> added the comment:
This looks like a reasonable use case. That being said, I question whether the defaults should be attached directly to the template instance or whether they should be part of the substitution method.
FWIW, there already have a couple of other ways to do it:
>>> from string import Template
>>> s = Template("${user} made me a ${flavor} cake.")
>>> default = {"user":"Dennis"}
>>> s.substitute(default, flavor='vanilla')
'Dennis made me a vanilla cake.'
>>> s.substitute(default, user='Ken', flavor='vanilla')
'Ken made me a vanilla cake.'
>>> from collections import ChainMap
>>> s.substitute(ChainMap(dict(flavor='vanilla'), default))
'Dennis made me a vanilla cake.'
----------
assignee: -> rhettinger
nosy: +rhettinger
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue13173>
_______________________________________
More information about the Python-bugs-list
mailing list