How can I allow users to execute mathematical expressions in a safe way? Do I need to write a full parser?
Is there something like ast.literal_eval(), but for expres
Few weeks ago I did similar thing, but for logical expressions (or, and, not, comparisons, parentheses etc.). I did this using Ply parser. I have created simple lexer and parser. Parser generated AST tree that was later use to perform calculations. Doing this in that way allow you to fully control what user enter, because only expressions that are compatible with grammar will be parsed.