3 ms·
`eval()` is such a serious code smell. I will admit that I've used it, though. I have an IRC bot written in Python with a "!calc" command that calls eval().
by Sohcahtoa82 5y ago
`eval()` is such a serious code smell.
I will admit that I've used it, though. I have an IRC bot written in Python with a "!calc" command that calls eval(). But I use `ast` to build the syntax tree, then walk it and compare every AST object to a white list so you can only use numbers and math operators. Anything else, such as CALLs or strings will throw an error.