i wand to save some config values to a text file so i can use them later on in my code, so i decided on saving it into a text file in a JSON format but when i try and read the value from the file i get an error
json.decoder.JSONDecodeError: Expecting property name enclosed in double quotes: line 1 column 2 (char 1)
the text file content is:
"{'EditDate': 1497014759002}"
import json
import os
cPath = os.path.dirname(os.path.realpath(__file__))
configPath = cPath+'/tt.txt'
ConfigStr = {"EditDate" : 1497014759002}
print(ConfigStr)
print("-----------")
with open(configPath, 'w') as outfile:
json.dump(repr(ConfigStr), outfile)
with open(configPath) as json_data:
d = json.load(json_data)
jstr = d
print(jstr)
print("-----------")
a = json.loads(jstr)
lastedit = a['EditDate']
print(lastedit)
dumpedstr(ConfigStr)instead. Also, notice thatConfigStris a dictionary, not a string, so the name is misleading.just.dump()a Python representation ofConfigStr, just pass thedicttojson.dump()as it is.json.dump(config, open(configPath, 'w'))