I have a Python file that has a variable defined using sympy. For instance, let us take the following (crazy) example that I could have eventually since I am automatizing a routine:
from sympy import * e=symbols('e') a=e*10**(-100)-sin(e**2-1)+cos(e*10**(-50)+1) file=open('file.txt','w') file.write(str(a)) file.close()
After this, the file is saved in the following way:
1.0e-100*e - sin(e**2 - 1) + cos(1.0e-50*e + 1)
I would like to open this file in Mathematica and save the output as a variable in Mathematica format.
The problem here is that to replace
*^ is not an option since
e is a parameter of the variable that is being saved so that would change even the variable
e. An interesting fact about this is that when
e is followed immediately by an integer, then the meaning of the
*^. However, I don't know how to check that. Besides, I haven't been able to find a way to change the trigonometric functions into Mathematica input since the arguments of those functions could be anything.
Up until now, I have solved the problem with sqrt and general exponents but I don't know how to deal with the scientific notation and trigonometric functions.
EDIT: Up until now it seems that this solves the problem with
e in Mathematica:
file=Import["file.txt"] file = StringReplace[file, "**" -> "^"] file = StringReplace[file, "e" -> "*^"] file = StringReplace[file, "*^ " -> "e "] file = StringReplace[file, "*^^" -> "e^"] file = StringReplace[file, "*^*" -> "e*"]
Yet I am not sure if there is another method to solve it or if that would solve all the problems with the