byoc.arithmetic_eval
- byoc.arithmetic_eval(expr: str) Union[int, float]
Evaluate the given arithmetic expression.
- Parameters
expr – The expression to evaluate. The syntax is identical to python, but only
int
literals,float
literals, binary operators (except left/right shift, bitwise and/or/xor, and matrix multiplication), and unary operators are allowed.- Returns
The value of the given expression.
- Raises
SyntaxError – If expr cannot be parsed for any reason.
TypeError – If the expr argument is not a string.
ZeroDivisionError – If expr divides by zero.
It is safe to call this function on untrusted input, as there is no way to construct an expression that will execute arbitrary code.