Currently I have this code, which reads from a file containing something similar to [{'1': {'Score': '2', 'Class': '3'}}] and assigns it to a variable:
exec('assigns = ' + open(r'D:\Dropbox\Dev\Output\dict', 'r').read())
However, I have been told that using exec is dangerous. How can I write the same code without using exec?
Use
ast.literal_eval():It will only evaluate literals, no function calls or operators.