export - How to output an expression to an external file in "plain text" format without breaking lines?
Given a pretty long expression, such as
a={-11 ψ^2 λ[1]+6 ψ λ[2],35 ψ^2 λ[2],11 ψ^2 λ[1]^2-11 ψ^2 λ[2]-6 ψ λ[1] λ[2],ψ^2 λ[1]^2-ψ^2 λ[2]-ψ λ[1] λ[2]+λ[2]^2,-λ[1]^3+2 λ[1] λ[2],-3 ψ λ[1]^3+6 ψ λ[1] λ[2]+λ[1]^2 λ[2]-λ[2]^2,-ψ λ[1]^3+λ[1]^4+2 ψ λ[1] λ[2]-3 λ[1]^2 λ[2]+λ[2]^2}
a >> tmp
would output the expression of a
to an external file tmp
. But I don't like the format in this output. It breaks lines, and contains extra spaces between operators of "+-*/".
In fact, in Mathematica, selecting an expression, we could do (right click) > Copy as > Plain Text, and then we could paste it to any external text editor without any problem.
Is it possible to specify the output stream using this "Plain Text" format above?
Answer
Export["test.txt", {a}]
works for me
"Plaintext"
is already the default output form of Export
. The { }
around a
prevents Export
from seeing it as a series of arguments (a
is a list in your example) that each have to be put on its own line.
Comments
Post a Comment