string interpolation syntactic sugar
Fredrik Lundh
fredrik at pythonware.com
Thu Dec 9 10:25:22 EST 1999
Dickon Reed <dr10009 at cl.cam.ac.uk> wrote:
> I propose a new kind of string literal wherein bracketed expressions
> are evaluated then converted to strings.
argh!
> An alternative approach might have a function to do this:
>
> interpolate("a {x} b {y}")
that's reasonable.
> I wonder if this could be implemented as a library service (if it
> hasn't already been done). Is it as simple as chopping up the string
> and calling str(eval(foo)) on each bracketted component? The place I
> come unstuck with this is obtaining the globals and locals of the
> caller so that the expressions are evaluated in the environment where
> interpolate is called.
I'm not sure if it works with 1.5.2, but Ping's string
interpolation module implements most of this (with
a slightly different syntax).
start here:
http://www.lfw.org/python/
</F>
More information about the Python-list
mailing list