[Python-ideas] Template.match or similar (was Re: Where/how to propose...)

Joe Strout joe at strout.net
Mon Oct 13 23:09:10 CEST 2008


On Oct 13, 2008, at 2:43 PM, Terry Reedy wrote:

> Given that I have never used the Template class and am using 3.0  
> str.format, that I believe the former was the bridge that led to the  
> latter, and am not enamored of writing REs, I think adding str.match  
> would be a great idea.  To the extent possible,
>  s  == form.format(form.match(s)) and
>  args == form.match(form.format(args).
> Note that args can either be a sequence or mapping.
>
> This might encourage more people to switch faster from % to .format.  
> Given that Guido wants this to happen, he might look favorably

Well, I'm all for that, but I've never used the 3.0 str.format, and  
find the documentation on it somewhat unenlightening.  Can you mock up  
an example of how this might work?

In simple form it looks very similar to Template.substitute, but it  
leaves lots of room for getting not-so-simple.  Does that present a  
problem, in that a great number of format strings would not be useable  
in reverse?  Or would we simply say: if you want to use the reverse  
(match) operation, then you have to restrict yourself to simple named  
fields?  Or, would we define a slightly different syntax for use with  
match, that lets you specify numeric conversions or whatever, and give  
up the idea that these are truly inverse operations?

Best,
- Joe




More information about the Python-ideas mailing list