[Python-Dev] PEP 215 redux: toward a simplified consensus? (original) (raw)
Guido van Rossum guido@python.org
Mon, 25 Feb 2002 17:04:04 -0500
- Previous message: [Python-Dev] PEP 215 redux: toward a simplified consensus?
- Next message: [Python-Dev] PEP 215 redux: toward a simplified consensus?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
There are two entirely different potential uses for interpolation. One is for the Python programmer; call this literal interpolation. It's cute to be able to write
a = 12
b = 15
c = a*b
print <span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi mathvariant="normal">"</mi><mi>A</mi><mi>r</mi><mi>e</mi><mi>c</mi><mi>t</mi><mi>a</mi><mi>n</mi><mi>g</mi><mi>l</mi><mi>e</mi><mi>o</mi><mi>f</mi></mrow><annotation encoding="application/x-tex">"A rectangle of </annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.8889em;vertical-align:-0.1944em;"></span><span class="mord">"</span><span class="mord mathnormal">A</span><span class="mord mathnormal">rec</span><span class="mord mathnormal">t</span><span class="mord mathnormal">an</span><span class="mord mathnormal" style="margin-right:0.03588em;">g</span><span class="mord mathnormal" style="margin-right:0.01968em;">l</span><span class="mord mathnormal">eo</span><span class="mord mathnormal" style="margin-right:0.10764em;">f</span></span></span></span>a x <span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>b</mi><mi>h</mi><mi>a</mi><mi>s</mi><mi>a</mi><mi>n</mi><mi>a</mi><mi>r</mi><mi>e</mi><mi>a</mi><mi>o</mi><mi>f</mi></mrow><annotation encoding="application/x-tex">b has an area of </annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.8889em;vertical-align:-0.1944em;"></span><span class="mord mathnormal">bha</span><span class="mord mathnormal">s</span><span class="mord mathnormal">ana</span><span class="mord mathnormal">re</span><span class="mord mathnormal">a</span><span class="mord mathnormal">o</span><span class="mord mathnormal" style="margin-right:0.10764em;">f</span></span></span></span>c."
This is arguably better than
print "A rectangle of", a, "x", b, "has an area of", c, "."
(and to get rid of the space between the value of c and the '.' a totally different paradigm would have to be used).
A totally different use of interpolation is for templates, where both the template (any data containing the appropriate $ syntax) and the set of variables to be substituted (any mapping) should be under full control of the program. This is what mailmail needs.
Literal interpolation has no security issues, if done properly. In the latter use, the security issues can be taken care of by carefully deciding what data is available in the set of variables to be interpolated. The interpolation syntax I've proposed is intentionally very simple, so that this is relatively easy. I recall seeing slides at the conference of a templating system (maybe Twisted's?) that allowed expressions like $foo.bar[key] which would be much harder to secure.
I18n of templates is easy -- just look up the template string in the translation database.
I18n of apps using literal interpolation is more of a can of worms, and I have no clear solution. I agree that a solution is needed -- otherwise literal interpolation would be worse than what we have now!
--Guido van Rossum (home page: http://www.python.org/~guido/)
- Previous message: [Python-Dev] PEP 215 redux: toward a simplified consensus?
- Next message: [Python-Dev] PEP 215 redux: toward a simplified consensus?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]