I'm running the following code:
asset = {}
asset['abc'] = 'def'
print type(asset)
print asset['abc']
query = '{"abc": "{abc}"}'.format(abc=asset['abc'])
print query
Which throws a KeyError error:
[user@localhost] : ~/Documents/vision/inputs/perma_sniff $ python ~/test.py
<type 'dict'>
def
Traceback (most recent call last):
File "/home/user/test.py", line 5, in <module>
query = '\{"abc": "{abc}"\}'.format(abc=asset['abc'])
KeyError: '"abc"'
Format is obviously getting confused by the wrapping {. How can I make sure format only tries to replace the (correct) inner {abc}.
ie, expected output is:
{"abc": "def"}
(I'm aware I could use the json module for this task, but I want to avoid that. I would much rather use format.)