I'm not sure why you want this format, especially since it will not be valid for reading in any other application, but it doesn’t matter.
The problem is that to write a dictionary into a file, you need to convert it to a string - and for this, Python calls reprfor all its elements.
If you create output manually as a string, all is well:
d = "{'key': '%s'}" % w
with io.open('testtt.sql', mode='a', encoding='UTF8') as f:
f.write(d)
source
share