I need to read dict values from a config file that contain regular expressions. One solution I saw was to read as json and convert. I tried this solution but it doesn't work:
My file contains this dict:
{"my_word":"word\s"}
Then in the script:
import json
with open('config_dict.ini') as f:
data = f.read()
js = json.loads(data)
print(js)
But I get the error "JSONDecodeError: Invalid \escape". So I tried to escape the slash:
{"my_word":"word\\s"}
And there's no error but it reads the dict as is, which isn't going to work when I use the regex.
Is there another way to read a dict? It doesn't have to include json.
Edit: I tried this solution but it doesn't work. And anyway it's going to be messy if I have to add so many escapes to the regex.