saving the data after it was printed to screen python
<p>Is there a way to save data after it was printed to the screen? 
for example: 
lets have some arbitrary function</p>

<pre><code>def main():
    if something:
       for i in range(n):
           output= "%f %f" %(n,d)
           print output

    if something:
       for i in range(n):
           output="%f %f" %(n,d)
           print output

    fileout=open("data.csv", "a")
    fileout.write(output)
</code></pre>

<p>this will only write the last data for the last range in for loop.</p>

<p>Edit: I want to ask a user if she/he wants to save that data</p>
