[Python-ideas] String interpolation for all literal strings
Barry Warsaw
barry at python.org
Thu Aug 6 23:53:51 CEST 2015
On Aug 06, 2015, at 03:37 PM, Yury Selivanov wrote:
>What if we introduce f-strings in the following fashion:
>
>1. ``f'string {var}'`` is equivalent to
>``'string {var}'.format(**locals())`` -- no new formatting
>syntax.
You really do want to include globals too, with locals overriding them.
>2. there is a 'sys.set_format_hook()' function that allows
>to set a global formatting hook for all f-strings:
>
> # pseudo-code
> def i18n(str, vars):
> if current_lang != 'en':
> str = gettext(str, current_lang)
> return str.format(vars)
>
> sys.set_format_hook(i18n)
>
>This would allow much more convenient way not only to format
>strings, but also to integrate various i18n frameworks:
>
> f'Welcome, {user}' instead of _('Welcome, {user}')
I don't think you want this to be a process-global hook since different
modules may be using a different i18n systems.
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/20150806/f5571b4e/attachment.sig>
More information about the Python-ideas
mailing list