Write data to a file in Python
<p>First of all I have to say I am completely new with python as I am doing my friend's homework (I've just finished an exponential fitting so I have almost 3 hours experience of python). That said here is my question: How can I save data to a file (that I will plot later on) effectively?</p>

<p>I have got this from my research:</p>

<pre><code>#Open new data file
f = open("data2.txt", "w")
f.write( str(yEst)  )      # str() converts to string
f.close()
</code></pre>

<p>Here is a bit of my code so far:</p>

<pre><code>for i in drange2(0, 2*math.pi + 0.0634665182543392 , 0.0634665182543392):
    for x in range(1,N+1):
       yEst = yEst + a * cos(x* i)
#print yEst
f.write( str(yEst)  )      # str() converts to string
yEst=0
f.close()
</code></pre>

<p>Now, when I go and open my file "<code>data2.txt</code>" I can not read the data because it is not 'organized'. How can I go to the next line using the <code>f.write( str(yEst)  )</code> so that I have a column that contains my 'yEst' data into the file "data2.txt?
Thank you in advance for your consideration :)</p>

<p>PS: yEst looks like (in the data2.txt file): <code>48.901347147148.605785828748.114506165947.429486 ..</code> and I want it as a column: --></p>

<pre><code>48.9013471471 (go to the line)
48.6057858287 (GTTL)
48.1145061659  (GTTL)
47.4294863684    
etc ..                        
</code></pre>
