[Python-ideas] Briefer string format

Stephen J. Turnbull stephen at xemacs.org
Wed Jul 22 02:11:10 CEST 2015


Mike Miller writes:
 > My apologies, as I've read through this thread again and haven't found the 
 > reason the approach last mentioned by Eric S. was abandoned:
 > 
 >      f'{a[name]}'  ==>   '{[name]}'.format(a)
 > 
 > This seemed to solve things neatly, letting .format() handle the
 > messy details it already handles.

That's what I thought, too, but according to
https://mail.python.org/pipermail/python-ideas/2015-July/034728.html,
that's not true.  The problem is that .format accepts *arbitrary*
expressions as arguments, eg "{a.attr}".format(a=f()), which can't be
expressed as an f-string within the limits of current .format specs.
Finally Eric concludes that you end up with a situation where format
would need to be called directly, and str.format isn't involved at all
I haven't studied the argument that leads there, but that's the
context you're looking for, I believe.

Python-Ideas meta:

The simple implementation is surely still on the table, although I get
the feeling Guido is unhappy with the restrictions implied.  However,
it is unlikely to be discussed again here precisely because those who
understand the implementation of str.format well already understand
the implications of this implementation very well -- further
discussion is unnecessary.

In fact, Guido asking for a PEP may put a "paragraph break" into this
discussion at this point -- we have several proposed implementations
with various amounts of flexibility, and the proponents understand
them even if I, and perhaps you, don't.  What's left is the grunt work
of thinking out the corner cases and creating one or more proof-of-
concept implementations, then writing the PEP.

Steve


More information about the Python-ideas mailing list