[Python-ideas] Draft PEP on string interpolation

Nick Coghlan ncoghlan at gmail.com
Sat Aug 22 00:59:20 CEST 2015


On 22 August 2015 at 05:52, Mike Miller <python-ideas at mgmiller.net> wrote:
> Yes, we were discussing these custom prefixes in Yuri's thread yesterday,
> but Guido dropped a big -1 there.  However, you Eric and Nick make some
> compelling arguments in favor of them; they do solve several of our
> outstanding issues.
>
> Would he be able to be persuaded to change his mind?

It's also worth reiterating my concept of using "!" to introducing the
arbitrary "magic happens here" prefixes. That is, you'd write them
like this:

    myquery = !sql"SELECT $column FROM $table;"
    mycommand = !sh"cat $filename"
    mypage = !html"<html><body>$content</body></html>"

I'd previously suggested a syntax along those lines for full compile
time AST manipulation where the compiler also had to be made aware of
the prefix names somehow, but I think the proposals that have evolved
around f-strings make it possible to instead resolve the named
reference at runtime, while still having the compiler handle the
subexpression extraction and evaluation.

Regards,
Nick.

-- 
Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia


More information about the Python-ideas mailing list