Draft PEP: string interpolation with backquotes

Fernando Pérez fperez528 at yahoo.com
Sun Dec 2 00:54:57 CET 2001


Greg Ewing wrote:

> Also, what is the parser supposed to make of things like
> 
>   $"x is $x & y is $y"
> 
> ? Is it supposed to be smart enough to realise that it
> has to stop after "x" and not try to interpret the rest
> as an '&' operator followed by a variable followed by
> an 'is' operator followed by a syntax error?
> 
> I think that "as far as it can be evaluated" is too
> fuzzy a specification. Even if the parser can be taught
> to understand exactly what it means, I'm not sure that
> humans can...

I should just have quoted the pep. You are right, "as far as it can 
be evaluated" is a bad way to say it. PEP 215: 
http://python.sourceforge.net/peps/pep-0215.html
The details are there.

As far as the above, it's actually simple:

In [1]: from Itpl import itpl
In [2]: x=4
In [3]: y=5
In [4]: itpl('$x+y')
Out[4]= '4+y'
In [5]: itpl('${x+y}')
Out[5]= '9'

The $ grabs out to operators only. The pep gives more details.

Cheers,

f



More information about the Python-list mailing list