I'd like to print something like the string below using Python:
{"_id":ObjectId("5a43ae09e2bae06ddd400dfc")}
At first I thought it would be easy, but it is not.
Here is my first attempt:
'{"_id":ObjectId("{}")}'.format('5a43ae09e2bae06ddd400dfc')
But I got the following error
Traceback (most recent call last): File "", line 1, in KeyError: '"_id"'
Then I tried:
'\{"_id":ObjectId("{}")\}'.format('5a43ae09e2bae06ddd400dfc')
And I got this error
Traceback (most recent call last): File "", line 1, in KeyError: '"_id"'
I managed to make it work with the following code:
'{"_id":ObjectId("%s")}' %('5a43ae09e2bae06ddd400dfc')
'{"_id":ObjectId("5a43ae09e2bae06ddd400dfc")}'
What's wrong with str format?