[Python-Dev] Re: PEP 292, Simpler String Substitutions

Paul Prescod paul@prescod.net
Sun, 23 Jun 2002 12:36:34 -0700


Christian Tismer wrote:
> 
>...
> 
> Are you sure you got what I meant?
> I want to compile the variable references away at compile
> time, resulting in an ordinary format string.
> This string is wraped by the runtime _(), and
> the result is then interpolated with a dict.

How can that be?

Original expression:

_($"$foo")

Expands to:

_("%(x1)s"%{"x1": foo})

Standard Python order of operations will do the %-interpolation before
the method call! You say that it could instead be 

_("%(x1)s")%{"x1": foo}

But how would Python know to do that? "_" is just another function.
There is nothing magical about it. What if the function was instead
re.compile? In that case I would want to do the interpolation *before*
the compilation, not after!

Are you saying that the "_" function should be made special and
recognized by the compiler?

 Paul Prescod