[Python-ideas] Briefer string format

Ron Adam ron3200 at gmail.com
Sun Aug 2 21:29:39 CEST 2015



On 08/02/2015 11:37 AM, Eric V. Smith wrote:
> On 8/1/2015 1:43 PM, Eric V. Smith wrote:
>> On 7/25/2015 3:55 PM, Eric V. Smith wrote:

> If you want to put it in an f-string, you'd naively write:
>
>>>> f'expr={{x: y for x, y in [(1, 2), (3, 4)]}}'
> 'expr={x: y for x, y in [(1, 2), (3, 4)]}'

This probably doesn't work either...

     f'expr={{{x: y for x, y in [(1, 2), (3, 4)]}}}'

Escaping "{{{" needs to resolve for left to right to work.  Which is weird.

> But as you see, this won't work because the doubled '{' and '}' chars
> are just interpreted as escaped braces, and the result is an
> uninterpreted string literal, with the doubled braces replaced by
> undoubled ones.
>
> There's currently no way around this. You could try putting a space
> between the left braces, but that fails with IndentationError:

Could two new escape characters be added to python strings?

      "\{" and "\}"

f'expr={\{x: y for x, y in [(1, 2), (3, 4)]\}}'


Ron




More information about the Python-ideas mailing list