[Python-ideas] Briefer string format

Guido van Rossum guido at python.org
Tue Jul 21 19:58:36 CEST 2015

On Tue, Jul 21, 2015 at 6:50 PM, Oscar Benjamin <oscar.j.benjamin at gmail.com>

> On Tue, 21 Jul 2015 at 14:14 Nick Coghlan <ncoghlan at gmail.com> wrote:
>> I wonder though, if we went with the f-strings idea, could we make
>> them support a *subset* of the "str.format" call syntax, rather than a
>> superset? What if they supported name and attribute lookup syntax, but
>> not positional or subscript lookup?
> Please don't do either. Python already has a surplus of string formatting
> mini-languages. Making a new one that is similar but not the same as one of
> the others is a recipe for confusion as well as an additional learning
> burden for new users of the language.

I'm not sure if you meant it this way, but if we really believed that, the
only way to avoid confusion would be not to introduce f'' strings at all.
(Which, BTW is a valid outcome of this discussion -- even if a PEP is
written it may end up being rejected.)

Personally I think that the different languages are no big deal, since
realistically the far majority of use cases will use simple variables (e.g.
foo) or single attributes (e.g. foo.bar).

Until this discussion I had totally forgotten several of the quirks of PEP
3101, including: a[c] meaning a['c'] elsewhere; the ^ format character and
the related fill/align feature; nested substitutions; the top-level
format() function. Also, I can never remember how to use !r.

I actually find quite unfortunate that the formatting mini-language gives
a[c] the meaning of a['c'] elsewhere, since it means that the formatting
mini-language to reference variables is neither a subset nor a superset of
the standard expression syntax. We have a variety of other places in the
syntax where a slightly different syntax is supported (e.g. it's quite
subtle how commas are parsed, and decorators allow a strict subset of
expressions) but the formatting mini-language is AFAIR the only one that
gives a form that is allowed elsewhere a different meaning.

--Guido van Rossum (python.org/~guido)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20150721/b6858698/attachment.html>

More information about the Python-ideas mailing list