"str"(expr)"str" interpolation syntax

Beni Cherniavsky cben at tx.technion.ac.il
Thu Sep 12 20:50:36 CEST 2002

"Mark McEahern" <marklists at mceahern.com> wrote on 2002-09-10:
> Beni Cherniavsky wrote:
> > I was searching for a new interpolation syntax ...
> <applying the brakes>
> You might be interested to:
> 1.  Checkout the PEPs for string interpolation and simple string
> substitution.
> 2.  Read this thread:
> http://groups.google.com/
> groups?selm=ouit4e63fr.fsf%40andlx-anamika.cisco.com
> 3.  Read the archives from Python-Dev regarding the relevant PEPs.
Read them all before (except py-dev but I dind't find much new there now).

> After you do all that, you may reconsider or reframe your suggestion in
> light of what has been discussed.
To tell the truth my idea looked nice while I tossed it in my head but when
I actually wrote the post I noticed that something doesn't look well...
The "Bleagh" reply said it best though perhaps a bit strongly :-)
Anyway I wanted to get feedback on how it looks to others.

As for the motivation [to answer the other posts]: I'm a happy user of
"%d" % x but I was targeting here the cases of long strings and other
reasons why PEPs 215 and 292 came to be.  I didn't like (and still don't)
the idea that I need to scan string literals for _code_.  Especially if I
might want to nest strings inside that code...  It can confuse editors but
that's a sign it can also confuse me.  I thought for a moment that I found
a nice solution but it turns out not to be nice...  Still I don't like
interpolations as in the PEPs.  [Never liked double quotes in perl/shell
either].  I'd rather stick to %s...

Maybe something very simple along the lines of:

subst("A template string - here: % it goes\n", foo,
      "Also multiple values: %, %\n", bar, quux,
      "Quoting percent (%) sings probably not needed...\n", '%')

could be useful...  Yes it smells like perl formats but the
intelacing of pictures/values is really near optimal IMHO.  I've just
read perl 6's plans for formats and they have hyphenation!  Beat me
if I want that in a language core ;-)

More information about the Python-list mailing list