Reputation: 1092
Is it possible to convert string to a calculable operation
I want to make this done:
>>> import math
>>> operation = "10/2*6 + math.sqrt(42)"
>>> compute(operation)
36.48074069840786
Upvotes: 0
Views: 191
Reputation: 23265
eval
will do that for you.
>>> import math
>>> operation = "10/2*6 + math.sqrt(42)"
>>> eval(operation)
36.48074069840786
Upvotes: 2