[Python-Dev] PEP-498: Literal String Formatting

Barry Warsaw barry at python.org
Mon Aug 10 13:48:54 CEST 2015


On Aug 09, 2015, at 06:14 PM, David Mertz wrote:

>That said, there *is* one small corner where I believe f-strings add
>something helpful to the language.  There is no really concise way to spell:
>
>  collections.ChainMap(locals(), globals(), __builtins__.__dict__).
>
>If we could spell that as, say `lgb()`, that would let str.format() or
>%-formatting pick up the full "what's in scope".  To my mind, that's the
>only good thing about the f-string idea.

That would certainly be useful to avoid sys._getframe() calls in my library,
although I'd probably want the third argument to be optional (I wouldn't use
it).

If '{foo}' or '${foo}' syntax is adopted (with no allowance for '$foo'), it's
very unlikely I'd use that over string.Template for internationalization, but
the above would still be useful.

Cheers,
-Barry


More information about the Python-Dev mailing list