[Python-Dev] Re: Update PEP 292

Raymond Hettinger python at rcn.com
Fri Aug 20 01:22:09 CEST 2004


[Tim]
> > I do object to this part:
> >
> >      If the $ character appears at the end of the line, or is
followed
> >      by any other character than those described above, it is
treated
> >      as if it had been escaped, appearing in the resulting string
> >      unchanged.
> >
> > There's already a facility to escape $, and it's dead easy to use.
$
> > isn't a frequently needed character either in most apps.  So
escaping
> > $ "by magic" too is, I think, more likely to make typing errors
harder
> > to find than to do anyone real good.

[Barry]
> What would you do about $'s at the end of the string?  I think the
> implementation would be much more complex if you didn't have this
rule,
> e.g. you'd have to match \$$ and the $-placeholder regexps would
> basically have to match everything.  Then the .sub call would have to
be
> more complex too, because it would have to check for the existence of
> those match groups and then raise an exception.  Or something like
that.

FWIW, Cheetah implements the behavior as described by Barry.

    IDLE 1.1a2      
    >>> from Cheetah.Template import Template
    >>> t = Template('the $rank is $@ a $$ dead ${rank}! $')
    >>> t.rank='king'
    >>> print t
    the king is $@ a $$ dead king! $

I think "escaping by magic" is the operational description.  A better
way to think of it is that only well formed substitutions are made.


Raymond



More information about the Python-Dev mailing list