If you want to run the code from user input (the contents of the file is entered), you will need eval or exec , by these names or some others (in particular, you need exec for operators - assignment of expression).
But you do not want (and should not) do this because it is evil, unsafe, completely unnecessary, etc. Release the task (just save the dict) and call re.compile , then you can use ast.literal_eval and you are completely safe (you still have to catch syntax errors and everything else that may go wrong to display a reasonable error message, but the malicious code should be close to the impossible, and itβs not so dirty). You can apply re.compile after download if you need.
source share