Sin[] does not exist in Python and while I can do FortranForm and similar things, I do not know of any PythonForm, is there anything built-in to convert an expression to Python?
Of course I can make rules like Sin[a_]->math.sin(a) but is going to be tedious and maybe somebody (at Wolfram) did this already?
I think the question is sufficiently different from this one 85445/convert-mathematica-math-expression-form-to-python-math-expression
Answer that I take from @masterxilo and I will keep updating as more known functions appear under my radar
PythonForm~SetAttributes~HoldAll
PythonForm[Sin[x_]] := StringTemplate["math.sin(``)"]@PythonForm@x
PythonForm[Cos[x_]] := StringTemplate["math.cos(``)"]@PythonForm@x
PythonForm[Log[x_]] := StringTemplate["math.log(``)"]@PythonForm@x
PythonForm[Rational[a_, b_]] :=
StringTemplate["(``/``)"][PythonForm@a, PythonForm@b]
PythonForm[Pi] := ToString["math.pi"]
PythonForm[Times[a_, b_]] :=
StringTemplate["(`` * ``)"][PythonForm@a, PythonForm@b]
PythonForm[Power[a_, b_]] :=
StringTemplate["(``**``)"][PythonForm@a, PythonForm@b]
PythonForm[Plus[a_, b_]] :=
StringTemplate["(``+``)"][PythonForm@a, PythonForm@b]
PythonForm[x_] := ToString@x;
PythonForm[f_Symbol[args___]] :=
StringTemplate["``(``)"][ToString@f, PythonForm@args]
PythonForm[args___] := (PythonForm /@ {args})~StringRiffle~", ";
->math.sin()because mathematica will take it as a dot product. You can do something like->mathdotsin()and fix it later with a string replace. Quite a hack though. – george2079 Aug 10 '16 at 16:44Dot[]might stand in your way. For now I am doing anInputFormof everything and then replacing in the python editor. ->.,^ ->**,[ -> (and]->).. awful but works, I was hoping in something more classy ... – Rho Phi Aug 10 '16 at 16:57