Problem:
Today I was trying to create a json file from Python and then I got this error: "AttributeError: module 'json' has no attribute 'dump'" and I found my solution here: http://stackoverflow.com/a/13612382/4064166
Solution:
So the problem was I named my file as json.py that was causing problems with json module so renaming it solved the issue.
Code:
import json
with open("dump.json", "w") as outfile:
json.dump({'number':6650, 'strings':'lorem ipsum', 'x':'x', 'y':'y'}, outfile, sort_keys = True, indent=4, ensure_ascii=False)
Screenshot:
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.