How to export data (which is as result of Python program) from commmand line?
Question: I am working on a Python program, and I have results on the command line.

Now I need to do analysis on the results, so I need all results as exported in
any format like either SQL, or Excel or CSV format.

Can some tell me how can i do that ?

    
    
    import csv
    x1=1 x2=2
    while True:
        show = [ dict(x1=x1+1 , x2=x2+2)]
        print('Received', show )
        with open('large1.csv','w') as f1:
            writer=csv.writer(f1, delimiter=' ',lineterminator='\n\n',)
            writer.writerow(show)
        x1=x1+1
        x2=x2+1 
    

Here this is infinite loop and I want to have a csv file containing 2 column
of x1 and x2. and with regularly updated all values of x1 and x2 row wise (1
row for 1 iteration)

But by this code I'm getting a csv file which is named as 'large1.csv' and
containing only one row (last updated values of x1 and x2).

So how can I get my all values of x1 and x2 as row was in python.


Answer: Have a look at the [open()
documentation](http://docs.python.org/2/library/functions.html#open).

Mode `w` will _truncate_ the file, which means it will replace the contents.
Since you call that every loop iteration, you are continuously deleting the
file and replacing it with a new one. Mode `a` appends to the file and is
_maybe_ what you want. You also might consider opening the file outside of the
loop, in that case `w` might be the correct mode.

