All i need to do is convert a String into an simple object like:
"1/4*x+ 1" to 1/4*x+ 1
I am extracting text from image and calculating the expression in the image.
If i get:
valid_text = 1/4*x+ 1= 1/6*x+ 1/2 from image, I am doing:
if 'x' in valid_text and '=' in valid_text:
lhs = valid_text.rsplit('=', 1)[0]
lhs = eval(lhs)
rhs = valid_text.rsplit('=', 1)[1]
rhs = eval(rhs)
solution = solve(Eq(lhs, rhs), x)
I am using eval() function to return an object when i pass a String into it. But eval() function sometimes gives
rhs = eval(rhs)
File "<string>", line 1, in <module>
TypeError: 'int' object is not callable` **AND other inappropriate outputs.**
Is there any other way to get an object from String?
It seems like you want to do symbolic calculus. python is not handling, as far as I know, this type of problem but the library simpy seems to do so. you can find information about it at http://scipy-lectures.github.io/advanced/sympy.html
Another approach would be to develop a grammar and syntaxic parser yourself but as already said, it's a long way to go.
Good luck!