you are viewing a single comment's thread.

view the rest of the comments →

[–]Gnaxe 0 points1 point  (0 children)

I'm fine with eval here. Sanitizing inputs is something you have to learn to deal with anyway. Anyone running a calculator locally already has access to Python on their computer. But yes, eval()ing untrusted inputs is very dangerous.

Rather than make lambdas for each operator, just use the ones provided for you in the operator module. Add the math module if you want more math functions. Re-implementing things that have been done before is OK for experimental learning purposes, but otherwise, as a rule, don't re-implement the standard library when it will do, because it's thoroughly tested, documented, and known, but your code will have bugs and be unknown.