[Python-Dev] Re: Alternative ImplementationforPEP292:SimpleString Substitutions

"Martin v. Löwis" martin at v.loewis.de
Sat Sep 11 10:39:14 CEST 2004


Raymond Hettinger wrote:
> [Brett]
> 
>>I suspect stating exactly what a valid Python
>>identifier contains as you did in parentheses above will be enough.
> 
> 
> Given the template, u'¿Puede volver $hoy o $mañana?', you think $ma is
> an intended placeholder name and that ñ should be a delimiter just like
> whitespace and punctuation?

No, I think Brett (and apparently nearly everybody else) thinks that
such a template will not be written over the course of the next five
years, except for demonstration purposes. Instead, what will be written
is u'¿Puede volver $today o $tomorrow?' because the template will be
a translation of the original English template, and, during translation,
placeholder names must not be changed (although I have difficulties
imagining possible values for today or tomorrow so that this becomes
meaningful).

> If end users always follow the rules, this will never come up.  If they
> don't, should there be error message or a silent failure?

There is always a chance of a silent failure in SafeTemplates, even with
this rule added - this is the purpose of SafeTemplates. With a Template,
you will get a KeyError. In any case, the failure will not be completely
silent, as the user will see $mañana show up in the output.

My prediction is that the typical application is to use Templates, as
users know very well what the placeholders are. Furthermore, the
typical application will use locals/globals/vars(), or dict(key="value")
to create the replacement dictionary. In this application, nobody
would even think of using mañana as a key, because you can't get
it into the dictionary.

If this never comes up, it is better to not complicate the rules.
Simple is better than complex.

Regards,
Martin



More information about the Python-Dev mailing list