str.format fails with JSON?
Jussi Piitulainen
jussi.piitulainen at helsinki.fi
Tue Feb 21 09:50:19 EST 2017
More information about the Python-list mailing list
Tue Feb 21 09:50:19 EST 2017
- Previous message (by thread): str.format fails with JSON?
- Next message (by thread): problems installing pylab
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
carlopires at gmail.com writes: > Hi, > > When I run this piece of code: > > 'From {"value": 1}, value={value}'.format(value=1) > > Python complains about the missing "value" parameter (2.7.12 and > 3.6.x): Perhaps you know this, but just to be sure, and for the benefit of any reader who doesn't: double the braces in the format string when you don't mean them to be interpreted as a parameter. > But according to the format string syntax > (https://docs.python.org/2/library/string.html): [- -] > So according to the specification, {value} should be recognized as a > valid format string identifier and {"value"} should be ignored. > > Python seems to not follow the specification in the documentation. > Anything inside the keys is accepted as identifier. I think raising an error is more helpful than ignoring it. I think.
- Previous message (by thread): str.format fails with JSON?
- Next message (by thread): problems installing pylab
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-list mailing list