On 07/08/2022 09:01, Anton Makarov wrote:
Hi, there! I use str function to convert sympy tree expression to infix math string. It works fine, except the case when i convert the expression in power, for example:
a = Symbol('a')
res = str(a**2)
print(res)
# a**2
Is there any way to convert sympy tree expression to Standart infix math string form:
a^2 instead of a**2 ?
Thanks...
--
You received this message because you are subscribed to the Google Groups "sympy" group. To unsubscribe from this group and stop receiving emails from it, send an email to sympy+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/sympy/d1eb5de6-6333-447d-9583-50fe7a0ac0ddn%40googlegroups.com <https://groups.google.com/d/msgid/sympy/d1eb5de6-6333-447d-9583-50fe7a0ac0ddn%40googlegroups.com?utm_medium=email&utm_source=footer>.

Why not simply take the math string and use Python to  replace "**" by "^" everywhere? That way you don't have to worry about the fact that "^" is a Python operator. You could also use the reverse replacement to 'reactivate' the string if necessary.

David

--
You received this message because you are subscribed to the Google Groups 
"sympy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sympy+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sympy/9881aa05-3a16-6479-2243-d349277faf9f%40dbailey.co.uk.

Reply via email to