[issue19824] string.Template: Add PHP-style variable expansion example

Barry A. Warsaw report at bugs.python.org
Thu Nov 28 18:35:15 CET 2013


Barry A. Warsaw added the comment:

On Nov 28, 2013, at 05:07 PM, anatoly techtonik wrote:

>This class could be more useful with the following example:
>
>>>> from string import Template
>>>> t = Template('$who likes $what')
>>>> who = 'tim'
>>>> what = 'kung pao'
>>>> t.substitute(locals())
>'tim likes kung pao'
>
>This will help PHP folks to transition their .php files.

I'm not sure what you want to add to the class.  Your example works out of the
box.  See this for an approach my third party library takes:

http://pythonhosted.org/flufl.i18n/docs/using.html#substitutions-and-placeholders

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue19824>
_______________________________________


More information about the Python-bugs-list mailing list