[Python-Dev] Extracting variables from string.Template objects

Aahz aahz at pythoncraft.com
Wed Jan 9 03:09:42 CET 2008


On Fri, Jan 04, 2008, Isaac Morland wrote:
> On Fri, 4 Jan 2008, Aahz wrote:
> 
>>>Also, on a related issue, does it make sense to scan the template
>>>string for invalid escape sequences in Template.__init__?  For the
>>>applications I can imagine of string.Template, I would prefer to get
>>>an error upon creating the Template object rather than arbitrarily
>>>later when I try to .substitute with it.
>>
>>No, create an is_valid() method at best.
> 
> I'm curious as to why.  Is it to avoid changing the behaviour of existing 
> code (i.e., backwards compatibility), or do you see a design problem with 
> having the Template constructor reject invalid template strings?

Mostly the former, though I'm not sure about the performance
implications of scanning on instance creation.
-- 
Aahz (aahz at pythoncraft.com)           <*>         http://www.pythoncraft.com/

Weinberg's Second Law: If builders built buildings the way programmers wrote 
programs, then the first woodpecker that came along would destroy civilization.


More information about the Python-Dev mailing list