[Python-Dev] Re: Update PEP 292 (original) (raw)
Tim Peters tim.peters at gmail.com
Fri Aug 20 19:50:41 CEST 2004
- Previous message: [Python-Dev] Re: Update PEP 292
- Next message: [Python-Dev] Re: Update PEP 292
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
[Raymond Hettinger]
I'm surprised that we're introducing a new API into the standard library and no one is showing the slightest interest in prior art. Cheetah is well thought out, fast, and mature (it's been through several evolutions in the wild). Also, the Cheetah designers started out by studying the existing art from ASP, JSP, PHP, PSP, and such. Templating and string substituion is not a new, yet the discussion here has the flavor of being thought up from scratch.
The current discussion is also just the latest in years of discussion. I've had 25 years of using string-interpolation gimmicks in countless contexts myself, and my preference is a reaction against the practical problems I had with "too much magic" in them (e.g., I can't remember the difference between {} vs (), so I know I'll make typos related to that; I also know I'll have no trouble remembering "if you want ,say<spanclass="katex"><spanclass="katex−mathml"><mathxmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow></mrow><annotationencoding="application/x−tex"></annotation></semantics></math></span><spanclass="katex−html"aria−hidden="true"></span></span>",anddespitethatI′llrarelywant, say <span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow></mrow><annotation encoding="application/x-tex"></annotation></semantics></math></span><span class="katex-html" aria-hidden="true"></span></span>", and despite that I'll rarely want ,say<spanclass="katex"><spanclass="katex−mathml"><mathxmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow></mrow><annotationencoding="application/x−tex"></annotation></semantics></math></span><spanclass="katex−html"aria−hidden="true"></span></span>",anddespitethatI′llrarelywant).
...
FWIW, I'm fine with that. It was a minor suggestion. Either way works.
The question is which works better. Let's make Guido decide .
My thought was that simpler string substitutions were going to be exposed to the end-user (non-programmers) and that they should not be harassed unnecessarily. However, these are easy errors to trap and report back to the user -- the only question being how to assign a line number to the exception (if I have a ten page user supplied template with an error, it would be great to tell them where it is).
Indeed! match_object.string
contains the original template string, and
match_object.start(4)
gives the index at which the unsubstitutable $ appeared. A string-relative line number can be computed from that, and/or surrounding context can be inserted in the exception detail.
- Previous message: [Python-Dev] Re: Update PEP 292
- Next message: [Python-Dev] Re: Update PEP 292
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]