[Python-Dev] Yet another string formatting proposal

Oren Tirosh oren-py-d@hishome.net
Thu, 21 Nov 2002 18:12:55 -0500


On Thu, Nov 21, 2002 at 05:00:44PM -0500, Paul Svensson wrote:
> On Thu, 21 Nov 2002, Oren Tirosh wrote:
> 
> >One advantage of using an operator, method or function over in-line
> >formatting is that it enables the use of a template. A new string method
> >can provide run-time evaluation of the same format:
> >
> >    "\(a) + \(b) = \(a+b)\n"
> >   r"\(a) + \(b) = \(a+b)\n".cook()
> >
> >A raw string is used to defer the evaluation of all backslash escape
> >sequences to some later time. The cook method evaluates backslash
> >escapes in the string, including any embedded expressions. This runtime
> >version may be used for internationalization, for example.
> 
> Why not call this method "eval", so we all will know to treat it with care ?

If cook() is limited to variable names it will be pretty safe and no 
special care should be necessary. In that case the example above wouldn't
work, though, because it contains (a+b). It will need to use cook_eval().

Since what it does is the opposite of "raw" I just had to call it "cook"!

	Oren