# Weird behaviour with PutAppend [duplicate]

I'm a Mathematica newbie and I'm trying to append some data to a file but I am experiencing some weird behaviour when using PutAppend.

Here is what I am doing:

AbsVal[T_, numofterms_, a_] := Abs[B2[T, numofterms, a]/numint[T, a]][[1]]

For[n = 1, n < 500, n += 5, PutAppend[Flatten[{n, AbsVal[t, n, a]}], "myfile.txt"]]


I'll now give you example of the outputs. For

AbsVal[t, n, a]


I get an output with the following format:

3.090061579944379*10^-416


But in my file I see

{1,
6.63439871279507883794103547019190317447825626399276715.954589770191005*^-4\
30}
{6, 3.090061579944378840918744225967817269549146984115.954589770191005*^-416}
{11, 2.145574383018822357551113588639998485685515.954589770191005*^-403}
{16,
2.272995046809765497070946356598873140903263071672241715.954589770191005*^-\
391}
{21, 6.006641166397704104654654669842874619572668315.954589770191005*^-380}
{26, 5.3106240816580319132356313418534881615.954589770191005*^-369}
{31,
1.902243066216566879788057388396943157810258138515.954589770191005*^-358}
{36, 3.156766258003955178899483197047642127115.954589770191005*^-348}
{41,
2.6797936191463468007055797110923090995931447212315.954589770191005*^-338}
{46, 1.2557484218734034808224174859992025804315.954589770191005*^-328}
{51, 3.45010940785042836269827692329249391048639894815.954589770191005*^-319}
{56, 5.836346255402319616357043386100018580415.954589770191005*^-310}
{61, 6.330104189030497*^-301}
{66, 4.55439511956804*^-292}
{71, 2.237735694265989*^-283}
{76, 7.698747588846684*^-275}
{81, 1.895566134531356*^-266}
(...)


which I think is very weird because:

• In the first line, there is a linebreak between 1, and 6.6343987(blah blah blah)
• Sometimes I have that weird 15.954589770191005 term with that weird apostrophe (which I have no idea what it means)
• Also sometime I get a backslash \ when the line gets too long

As you have noticed, this is all very weird to me!!

What I'm aiming for is for a consistent output like the one we see in the last five lines. What I was REALLY aiming for is to have a csv format as output (without the curly brackets)

What am I doing wrong? or what do I need to configure to fix this?

Thank you very much!

• @T.P.Vasconcelos No worry, you cannot directly delete the comment or answer of others by clicking on them :) It may have been removed by sblom when you were voting up. – user31159 Nov 10 '16 at 1:03
• @T.P.Vasconcelos No, not even on your own question. See edited comment above for the second question. – user31159 Nov 10 '16 at 1:06
• Use Export. Put will write Mathematica expressions, and you don't want Mathematica syntax in your output. The usual way to export data is to first generate all of it, then Export a whole list in one go. Always do this unless you know why you need to append step by step. If you're new to Mathematica forget about For completely, as it will be counterproductive to your learning. For procedural loops use Do instead, or While when needed. But try to avoid procedural loops. The right way to deal with your example is to generate data with Table, then Export. – Szabolcs Nov 10 '16 at 7:59
• The link above is about appending in CSV format, for the rare cases when that is necessary. But do consider something like this first: result = Table[{n, AbsVal[t, n, a]}, {n, 1, 50, 5}]; Export["output.csv", result]. – Szabolcs Nov 10 '16 at 12:57
• – Alexey Popkov Nov 10 '16 at 14:12

Found the answer to my question!!

For[n = 1, n < 50, n += 5, {n, FortranForm[AbsVal[t, n, a]]} >>> "myfile.txt"]


which appends the following output to myfile.txt

{1, 6.634398712795079e-430}
{6, 3.090061579944379e-416}
{11, 2.145574383018822e-403}
{16, 2.272995046809765e-391}
{21, 6.006641166397704e-380}
{26, 5.310624081658032e-369}
{31, 1.902243066216567e-358}
{36, 3.156766258003955e-348}
{41, 2.679793619146347e-338}
{46, 1.255748421873403e-328}
`

I'm happy with this for now!