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

2017-03-26 Thread Barry A. Warsaw
Barry A. Warsaw added the comment: We should really restructure string.Template documentation to emphasize i18n. That's always been its prime use case, and f-strings don't change that (because f-strings are not really appropriate for translations). Before f-strings, string.Template had other

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

2017-03-26 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: Formatting with locals() and globals() should be used with careful. This is not the most idiomatic way of formatting. I think that the post in specialised blog would be better place for describing it than Python stdlib documentation. Peoples coming from PHP

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

2013-11-28 Thread Barry A. Warsaw
Barry A. Warsaw added the comment: A few notes about flufl.i18n's style. We chose this (extracted from the GNU Mailman project) because $strings are *way* less error prone for translators than %s strings, especially when you consider that some languages change the order of placeholders. The aut

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

2013-11-28 Thread anatoly techtonik
anatoly techtonik added the comment: @Alex, have you seen http://pythonhosted.org/flufl.i18n/docs/using.html#substitutions-and-placeholders? I really like the brevity, and it is the function that does the magic, so it is fully transparent and you don't need to instantiate string.Template every

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

2013-11-28 Thread Alex Gaynor
Alex Gaynor added the comment: Using locals() in this fashion is a serious anti-pattern, I'm -∞ on the docs suggesting it. -- nosy: +alex ___ Python tracker ___

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

2013-11-28 Thread anatoly techtonik
anatoly techtonik added the comment: There is nothing to add to the class itself. It is about expanding docs section with helpful examples. `string.Template` is undervalued, because it is hard to see how it can be more useful than standard string formatting functions. But for people coming fro

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

2013-11-28 Thread Barry A. Warsaw
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()) >'ti

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

2013-11-28 Thread Barry A. Warsaw
Changes by Barry A. Warsaw : -- nosy: +barry ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.pytho

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

2013-11-28 Thread anatoly techtonik
New submission from anatoly techtonik: http://docs.python.org/2/library/string.html#template-strings 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())