[Python-ideas] template strings

MRAB python at mrabarnett.plus.com
Tue Aug 18 01:24:22 CEST 2015


On 2015-08-17 21:13, Yury Selivanov wrote:
> In ECMAScript 6 there is a concept of Template Strings [1]. What if we add
> something similar in Python?
>
> Some key ideas
> --------------
>
> 1. Template Strings (TS) will be built on top of PEP 498 machinery (if
> accepted).
>
> 2. The syntax will match the following:
>
>       {python identifier}{optional whitespace}{string literal}
>
> where "python identifier" can be any valid python name *except* r, u, b,
> or f.
>
[snip]

What happens if you accidentally omit a comma?

     print(count ' items found')

Currently it's a syntax error, but, with this proposal, it becomes a
runtime error:

     AttributeError: 'int' object has no attribute '__format_str__'



More information about the Python-ideas mailing list