Skip to content

Instantly share code, notes, and snippets.

@epifanio
Created October 5, 2019 18:45
Show Gist options
  • Save epifanio/98698db4f23a7cc9f4b97d2cb1d13ba7 to your computer and use it in GitHub Desktop.
Save epifanio/98698db4f23a7cc9f4b97d2cb1d13ba7 to your computer and use it in GitHub Desktop.
name = 'n'
type = 't'
stored = 'true'
data = '{\n "add-field":{\n "name":"%s",\n "type":"%s",\n "stored":%s }\n}' % (name, type, stored)
data
@epifanio
Copy link
Author

epifanio commented Oct 5, 2019

while using str.format() :

data = '{\n  "add-field":{\n     "name":"{name}",\n     "type":"{type}",\n     "stored":{stored} }\n}'.format(name=name, type=type, stored=stored)

i got:

---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
<ipython-input-26-1c58c43a20c5> in <module>
----> 1 data = '{\n  "add-field":{\n     "name":"{name}",\n     "type":"{type}",\n     "stored":{stored} }\n}'.format(name=name, type=type, stored=stored)

KeyError: '\n  "add-field"'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment