[Python-ideas] Briefer string format

Alexander Belopolsky alexander.belopolsky at gmail.com
Fri Jul 24 04:08:50 CEST 2015


On Thu, Jul 23, 2015 at 10:22 AM, Steven D'Aprano <steve at pearwood.info>
wrote:

> I don't think I want this behaviour:
>
>     f'{spam}' '{eggs}'
>     => format(spam) + '{eggs}'
>
> for two reasons. Firstly, I already have (at least!) one way of getting
> that behaviour, such as explicit + concatenation as above.
>
> Secondly, it feels that this does the concatenation in the wrong order.
> Implicit concatenation occurs as early as possible in every other case.
> But here, we're delaying the concatenation until after the format. So
> this feels wrong to me.
>
> (Again, I'm talking semantics, not implementation. Clever tricks with
> escaping the brackets don't matter.)
>

I don't know what you would call "Clever tricks with escaping", but I would
expect


 f'{spam}' '{eggs}'
 => '{spam}{{eggs}}'.format(**ChainMap(locals(), globals())

just as

'foo'r'bar'
=> 'foo\\bar'
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20150723/ba38352c/attachment.html>


More information about the Python-ideas mailing list