[Python-ideas] Briefer string format

Ryan Gonzalez rymg19 at gmail.com
Wed Jul 22 02:28:51 CEST 2015

Pretty sure I'm going to be odd one out, here...

I don't like most of Ruby, but, after using Crystal and CoffeeScript, I have fallen in love with #{}. It gives the appearance of a real expression, not just a format placeholder. Like:


On July 21, 2015 7:15:21 PM CDT, Chris Angelico <rosuav at gmail.com> wrote:
>On Wed, Jul 22, 2015 at 9:04 AM, Mike Miller
><python-ideas at mgmiller.net> wrote:
>> Second, there is an inconsistency in quoting of string dictionary
>> That's unfortunate, but the way format currently works.  Since f''
>will be
>> implemented on top, is not the quoting issue orthogonal to it?
>So I guess the question is: Does f"..." have to be implemented on top
>of str.format, or should it be implemented separately on top of
>object.__format__? The two could be virtually indistinguishable
>anyway. Something like this:
>loc = "world"
>print(f"Hello, {loc}!")
># becomes
>loc = "world"
>print("Hello, "+loc.__format__("")+"!")
># maybe with the repeated concat optimized to a join
>With that, there's no particular reason for the specifics of .format()
>key lookup to be retained. Want full expression syntax? Should be easy
>- it's just a matter of getting the nesting right (otherwise it's a
>SyntaxError, same as (1,2,[3,4) would be). Yes, it'll be a bit harder
>for simplistic parsers to work with, but basically, this is no longer
>a string literal - it's a compact syntax for string formatting and
>concatenation, which is something I can definitely get behind.
>REXX allowed abuttal for concatenation, so you could write something
>like this:
>msg = "Hello, "loc"!"
>Replace those interior quotes with braces, and you have an f"..."
>string. It's not a string, it's an expression, and it can look up
>names in its enclosing scope. Describe it alongside list
>comprehensions, lambda expressions, and so on, and it fits in fairly
>No longer -0.5 on this.
>Python-ideas mailing list
>Python-ideas at python.org
>Code of Conduct: http://python.org/psf/codeofconduct/

Sent from my Android device with K-9 Mail. Please excuse my brevity.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20150721/1b7afc6a/attachment.html>

More information about the Python-ideas mailing list