[Python-ideas] String interpolation for all literal strings

Nathaniel Smith njs at pobox.com
Thu Aug 6 09:25:15 CEST 2015


On Wed, Aug 5, 2015 at 11:27 PM, Nick Coghlan <ncoghlan at gmail.com> wrote:
>
> On 6 August 2015 at 16:05, Nathaniel Smith <njs at pobox.com> wrote:
> > I'm by no means prepared to mount a full defense / work out details / write
> > a PEP of this idea this week, but since IMO ! really is the only obvious
> > character to use for this, and now we seem to be talking about other uses
> > for the ! character, I wanted to get it on the radar...
>
> Fortunately, using "!" as a string prefix doesn't preclude using it
> for the case you describe, or even from offering a full compile time
> macro syntax as "!name(contents)".
>
> It's one of the main reasons I like it over "$" as the marker prefix -
> it fits as a general "compile time shenanigans are happening here"
> marker if we decide to go that way in the future, while "$" is both
> heavier visually and very specific to string interpolation.

I guess it's a matter of taste -- string interpolation doesn't strike
me as particularly compile-time-shenanigany in the way that macros
are, given that you could right now implement a function f such that

  f("...")

would work exactly like the proposed

  f"..."

with no macros needed. But it's true that both can easily coexist; the
only potential conflict is in the aesthetics.

-n

-- 
Nathaniel J. Smith -- http://vorpus.org


More information about the Python-ideas mailing list