Advertisement
DeaD_EyE

evaluate

Jun 24th, 2020
1,547
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.26 KB | None | 0 0
  1. """
  2. Read this: https://realpython.com/python-eval-function/#minimizing-the-security-issues-of-eval
  3. """
  4.  
  5. import math
  6.  
  7. def evaluate(user_input):
  8.     functions = {
  9.         "sin": math.sin,
  10.         "cos": math.cos,
  11.         "tan": math.tan,
  12.         "pi": math.pi,
  13.         "log": math.log
  14.     }
  15.     globals = {"__builtins__": {}}
  16.     return eval(user_input, globals, functions)
  17.  
  18.  
  19. evaluate("sin(pi * 2)")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement