How to add list values into a JSON file. Here is my code :
import os,string
drives_a = [chr(x) + ':' for x in range(65, 90) if os.path.exists(chr(x) + ':')]
How to add list values into a JSON file. Here is my code :
import os,string
drives_a = [chr(x) + ':' for x in range(65, 90) if os.path.exists(chr(x) + ':')]
Does this work for you?
import json
lst = [1,2,3]
file_name = 'test.json'
with open(file_name, 'w') as f:
f.write(json.dumps(lst))