When executing a expression with eval()
, the output for some input is wrong. I think the decimal values are not considered.
I have been trying to evaluate a string with python eval()
and also tried numexpr()
def _calc_line_base_amount(text):
num = '0123456789*-+/()'
# here text = "3/2*5"
if text:
for char in text:
if char not in num:
text = text.replace(char, "")
return eval(str(text))
and also tried this one too
import numexpr as ne
print(ne.evaluate("3/2*5"))
Input 3/2*5 Expected output 7.5 Actual Output is 5
Edit:: In python3+ It works. But I am running this python2.7