[Python-ideas] template strings
Yury Selivanov
yselivanov.ml at gmail.com
Tue Aug 18 02:24:43 CEST 2015
On 2015-08-17 7:24 PM, MRAB wrote:
> 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__'
>
Exactly. We can also (probably) use symtable to lookup 'count'
name and throw a SyntaxError if it's not defined.
Yury
More information about the Python-ideas
mailing list