New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
string.Template: Rewrite docs to emphasize i18n use case #64023
Comments
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())
'tim likes kung pao' This will help PHP folks to transition their .php files. |
On Nov 28, 2013, at 05:07 PM, anatoly techtonik wrote:
I'm not sure what you want to add to the class. Your example works out of the http://pythonhosted.org/flufl.i18n/docs/using.html#substitutions-and-placeholders |
There is nothing to add to the class itself. It is about expanding docs section with helpful examples. |
Using locals() in this fashion is a serious anti-pattern, I'm -∞ on the docs suggesting it. |
@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 time. I think its awesome. Do you have some explanations why passing locals() to string.Template is anti-pattern? I understand that passing "all that you have" is not good, but from my past experience with PHP I can't remember any problems that there are more names than I used. It is templating after all - what do you want to protect from? |
A few notes about flufl.i18n's style. We chose this (extracted from the GNU There is a potential security hole though - a malicious translator with access We've decided to accept the risks in exchange for the huge convenience. We've |
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 world can use f-strings. |
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 common uses. But f-strings do fulfill most other cases where people were using string.Template, so let's make sure that distinction is clear to people. |
Let's retitle this, then. |
In that case bpo-20314 looks related. |
I'll take this one, and see if I can address 20314 also. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: