Comment on Python string literals are kinda funnyparentComments−folkrav1moAm I understanding that you’re building JSON with string interpolation? If so any special reason you wouldn’t build a dict and json.dumps() it?−smitty1e1moWhen there is a multiline template, you can make it look natural withinjson_doc = '''{}''' % some_dictionaryand then populate json_doc via %(some_dictionary_key)s values inside of the brackets.I find it more readable.Furthermore, json_doc can now live elsewhere, if sizeable, and get imported.I guess that template strings may be the newer way to do this, but this is very backward compatible.
Comments
Am I understanding that you’re building JSON with string interpolation? If so any special reason you wouldn’t build a dict and json.dumps() it?
When there is a multiline template, you can make it look natural within
json_doc = '''{}''' % some_dictionary
and then populate json_doc via %(some_dictionary_key)s values inside of the brackets.
I find it more readable.
Furthermore, json_doc can now live elsewhere, if sizeable, and get imported.
I guess that template strings may be the newer way to do this, but this is very backward compatible.