[Python-ideas] String interpolation for all literal strings

Mike Miller python-ideas at mgmiller.net
Thu Aug 6 08:25:05 CEST 2015


Here I go again, just stumbled across this.

Apparently C# (an even more "appy" language) in the new version 6.0 went through 
this same discussion in the last year.  Here's what they came up with, and it is 
very close to the ideas talked about here:

     http://davefancher.com/2014/12/04/c-6-0-string-interpolation/
     https://msdn.microsoft.com/en-us/library/Dn961160.aspx

TL;DR - Interesting, they started with this syntax:

     WriteLine("My name is \{name}");

Then moved to this one:

     WriteLine($"My name is {name}");

I suppose to match C#'s @strings.  I think we're on the right track.

-Mike


On 08/05/2015 10:28 PM, Mike Miller wrote:
> Oscar and Nick bring up some important points.  Still, I don't think it will be
> as dangerous in the long run as it might appear ahead of time.  I say that *if*
> (and it's an important if), we can find a way to limit the syntax to the .format
> mini-language and not go the full monty, as a few of us worry.
>
> Also, remember the list of languages on wikipedia that have string
> interpolation?  People have made this trade-off many times and appear happy with
> the feature, especially in dynamic languages.
>
> I remember a PyCon keynote a few years back.  Guido said (paraphrasing...)
> "from a birds-eye view, perl, python, and ruby are all the same language.  In
> the important parts anyway."
>
> Like the other two, Python is also used for shell-scripting tasks, and
> unfortunately, it's the only one of those without direct string interpolation,
> which has probably hindered its uptake in that area.  It'd be useful everywhere
> though.
>
> So, let's not make perfect the enemy of pretty-damn awesome.  I've been waiting
> for this feature for 15 years, from back around the turn of the century *cough*,
> when I traded in perl for python.  ;)
>
> -Mike
>
>
> On 08/05/2015 09:18 PM, Nick Coghlan wrote:
>> On 6 August 2015 at 07:24, Oscar Benjamin <oscar.j.benjamin at gmail.com> wrote:
>>> On 5 August 2015 at 19:56, Eric V. Smith <eric at trueblade.com> wrote:
>>>>
>>>> In the "Briefer string format" thread, Guido suggested [1] in passing
>>>> that it would have been nice if all literal strings had always supported
>>>> string interpolation.
>
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> https://mail.python.org/mailman/listinfo/python-ideas
> Code of Conduct: http://python.org/psf/codeofconduct/
>


More information about the Python-ideas mailing list