[Python-ideas] Simplifying .format() based string interpolation

Haoyi Li haoyi.sg at gmail.com
Fri Feb 7 01:34:10 CET 2014


It already works!

from macropy.string_interp import macros, sA = 10B = 5print s["{A} +
{B} = {A + B}"]# 10 + 5 = 15

a, b = 1, 2print s["{a} apple and {b} bananas"]# 1 apple and 2 bananas



On Thu, Feb 6, 2014 at 4:11 PM, Chris Angelico <rosuav at gmail.com> wrote:

> On Fri, Feb 7, 2014 at 10:41 AM, Robert Hölzl <robert.hoelzl at posteo.de>
> wrote:
> > How about introducing new string tokens beginning with 'f',
> > which tells the parser to take over that job.
> > In this case one simply had to write:
> >
> > f"{name} is {value}  ({value:X} in hex)"
> >
> > and the parser would replace this by
> >
> > "{name} is {value}  ({value:X} in hex)".format(
> >     **collections.ChainMap(locals(), globals()) )
>
> PHP programmers would love it. Subsequent maintainers would hate it.
>
> It's way too magical for my liking.
>
> ChrisA
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> https://mail.python.org/mailman/listinfo/python-ideas
> Code of Conduct: http://python.org/psf/codeofconduct/
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20140206/b3d1907f/attachment.html>


More information about the Python-ideas mailing list