I have two lists:
{a, 1, b} and {b, 1.3, y}
My goal is to print them to file test.dat, so that the content of test.dat looks like:
(a 1 b)
(b 1.300 y)
I want the elements of the lists in the output file to be separated by spaces.
Questions:
- How can I do it?
- Is it possible to use Print command to do it?
Edit 1:
I was going along these lines:
myPrint[list_] := Print["(", Row[list, " "], ")"]
l1 = {a, 1, b};
myPrint[l1]
(a 1 b)
My problem is that I don't know how to export the results I got to a file. So this is the reason for my question 2.
Edit Final: Problem Solved
Solution by swish (from comments)
str = OpenWrite["test.dat"]
myPrint[list_] :=
WriteString[str, Row[{"(", Row[NumberForm[#, {4, 3}] & /@ list, " "], ")\n"}]]
l1 = {a, 1, b}
myPrint[l1]
Export[]? – J. M.'s missing motivation Apr 18 '13 at 11:05