str.format fails with JSON?

Carlo Pires carlopires at gmail.com
Tue Feb 21 10:19:24 EST 2017


Em terça-feira, 21 de fevereiro de 2017 11:39:13 UTC-3, Chris Angelico  escreveu:
> On Wed, Feb 22, 2017 at 1:23 AM,  Carlo Pires wrote:
> > Hi,
> >
> > When I run this piece of code:
> >
> > 'From {"value": 1}, value={value}'.format(value=1)
> 
> Firstly, this code is in error; I suspect you wanted a couple of
> literal braces, so what you want is:

What I wanted was an output without errors, like:

>From {"value": 1}, value=1

I think Python should ignore value not matching integers or identifiers. This will make str.format more robust and usable. It cannot be used if the text has JSON as string, for instance.



More information about the Python-list mailing list