[Python-ideas] String interpolation for all literal strings

Barry Warsaw barry at python.org
Fri Aug 7 18:16:54 CEST 2015


On Aug 07, 2015, at 07:50 PM, Nick Coghlan wrote:

>Not quite. While I won't be entirely clear on Eric's latest proposal
>until the draft PEP is available, my understanding is that an f-string
>like:
>
>    f"This interpolates \{a} and \{b}"
>
>would currently end up effectively being syntactic sugar for a
>formatting operation like:
>
>    "This interpolates " + format(a) + " and " + format(b)

Don't think of it this way, because this can't be translated.  For i18n to
work, translators *must* have access to the entire string.  In some natural
languages, fragments make no sense.  Keep this in mind while you're writing
your multilingual application. :)

>With that definition for default interpolation, the f-string above
>would be translated at compile time to the runtime call:
>
>    __interpolate__("This interpolates %s and %s", ("a", "b"), (a, b), ("",
>    ""))

You need named placeholders in order to allow for parameter reordering.

Cheers,
-Barry
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 819 bytes
Desc: OpenPGP digital signature
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20150807/ccf1d330/attachment-0001.sig>


More information about the Python-ideas mailing list