[Python-ideas] Briefer string format

Barry Warsaw barry at python.org
Fri Jul 31 23:37:28 CEST 2015


On Jul 19, 2015, at 04:35 PM, Mike Miller wrote:

>I've long wished python could format strings easily like bash or perl do, ...
>and then it hit me:
>
>     csstext += f'{nl}{key}{space}{{{nl}'
>
>An "f-formatted" string could automatically format with the locals dict.

You might take a look at a feature of flufl.i18n, which supports automatic
substitutions from locals and globals:

http://flufli18n.readthedocs.org/en/latest/docs/using.html#substitutions-and-placeholders

In general, flufl.i18n builds on PEP 292 $-strings and gettext to support more
i18n use cases, especially in multi-language contexts.  Still, the
substitution features can be more or less used independently, and do a lot of
what you're looking for.  This feature is only supported on implementations
with sys._getframe() though (e.g. CPython).

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/20150731/fba6c4e6/attachment.sig>


More information about the Python-ideas mailing list