I was trying to generate a dynamic id which comes from a an object at runtime and insert this into database.
'{"mykey": {value}}'.format(value=obj.id)
but this gives an error
KeyError: '"mykey"'
expected result:
'{"mykey": 4}' # assuming obj.id = 4
I know I can use json.dumps
but I do not wish to use json for such a simple task and had to resort to:'{"mykey": %s}' %(obj.id,)
But I am curious to know a way to do this with format.