0

Lets say I have a string "1*5/6*(7+8)". I need to evaluate this string without eval. How should I go about doing it?

The6thSense
  • 8,103
  • 8
  • 31
  • 65

1 Answers1

1

If it's not a problem for you to have sympy as dependency, you can use sympy.sympify.

>>> from sympy import sympify
>>> sympify("1*5/6*(7+8)").evalf()
12.5000000000000
beezz
  • 2,398
  • 19
  • 15