There is no problem opening the file.
JSON data is dict type, so you need to JSON-code to write it.
#Python 2 and 3 can be used
import json
with open('data.txt', 'w') as outfile:
json.dump(data, outfile)
Available in #Python 2.x
import io, json
with io.open('data.txt', 'w', encoding='utf-8') as f:
f.write(unicode(json.dumps(data, ensure_ascii=False)))
Available in #Python 3.x
import json
with open('data.txt', 'w') as f:
json.dump(data, f, ensure_ascii=False)
© 2024 OneMinuteCode. All rights reserved.