"str"(expr)"str" interpolation syntax
Sean 'Shaleh' Perry
shalehperry at attbi.com
Tue Sep 10 16:08:53 EDT 2002
On Tuesday 10 September 2002 12:35, Beni Cherniavksy wrote:
> Hi all.
> I was searching for a new interpolation syntax that would use quotes
> for starting/ending the interpolated part (I don't feel comfortable
> putting code inside unclosed quotes...)
> After contemplating some horrors like $"""str"expr"str""" or
> $("str" expr "str"), I noticed that currently both "( and )" are
> illegal (first because strings are not callable, second is a syntax
> error). So I propose that a parenthesized expresion near a string would
> imply concatenation. In other words,
> "foo"(x * 3)"bar"
> would be equivallent to
> "foo" + str(x * 3) + "bar".
> This works of course with only one side, e.g. "foo"(x) or (y)"bar" but in
> longer cases it would be good style to add empty strings on either end,
> e.g. ""(y)"bar". And of course it all works with single quotes too. One
> of the benefits over current interpolation PEPs is that you can change the
> quote type in the middle...
> What do you think?
having not read the PEPs, why is this needed?
s = "foo%dbar" % (x*3,) # this works
and as you showed above so does str(x*3).
More information about the Python-list