[Python-ideas] Briefer string format

Bruce Leban bruce at leban.us
Mon Jul 20 23:29:01 CEST 2015

On Mon, Jul 20, 2015 at 11:41 AM, Steve Dower <Steve.Dower at microsoft.com>

> Indexing is supported in format strings too, so f'{a[1]}' also becomes
> '{a[1]}'.format(a=a), but I don't think there are any other strange cases
> here. I would vote for f'{}' or f'{0}' to just be a SyntaxError.

Maybe I'm missing something, but it seems this could just as reasonably be

Is there a reason to prefer the other form over this?

On Mon, Jul 20, 2015 at 1:20 PM, Eric V. Smith <eric at trueblade.com> wrote:

> So:
> f'api:{sys.api_version} {a} size{sys.maxsize}'
> would become either:
> f'api:{.api_version} {} size{.maxsize}'.format(sys, a, sys)
> or
> f'api:{0.api_version} {1} size{0.maxsize}'.format(sys, a)

Or: f'api:{} {} size{}'.format(sys.api_version, a, sys.maxsize)

Note that format strings don't allow variables in subscripts, so

f'{a[n]}'  ==>   '{}'.format(a['n'])

Also, the discussion has assumed that if this feature were added it
necessarily must be a single character prefix. Looking at the grammar, I
don't see that as a requirement as it explicitly defines multiple character
sequences. A syntax like:


might be more readable. There's no namespace conflict just as there is no
conflict between raw string literals and a variable named r.

--- Bruce
Check out my new puzzle book: http://J.mp/ingToConclusions
Get it free here: http://J.mp/ingToConclusionsFree (available on iOS)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20150720/e1086188/attachment.html>

More information about the Python-ideas mailing list