[Python-Dev] Re: Re: Update PEP 292

Fredrik Lundh fredrik at pythonware.com
Wed Aug 11 21:16:58 CEST 2004


Barry Warsaw wrote:

> I specifically designed it so that you could subclass from template, so as to
> accept the extended placeholder syntax (i.e. dots), and then implement a
> mapping-like class to do the lookups in any namespace you want.

on the other hand, to do that, you need to replace the pattern, and
make sure that you have the same number of groups, with the same
meaning.  it's doable, but it's rather fragile.

two suggestions:

- refactor the RE, and use lastindex to extract the name (see the link
  I posted earlier).  This would let users add any number of patterns,
  without having to rewrite the __mod__ method.  And indexing by
  lastindex should be faster than tuple unpacking, too.

- Consider changing the ${} to accept arbitrary patterns, instead of
  just Python-style identifiers.  \${([^}]+)} should do the trick.

- Consider using character classes instead of re.IGNORECASE (easier
  to read, and IIRC, slightly faster).

</F> 





More information about the Python-Dev mailing list