Exporting in CSV file format for Python
Question: I am trying to export some content in CsV format..but not able to do.

Below is the arbitrary idea that i am doing in python.

    
    
    script , file = argv
    emails = open(file,"r") #opens the file 
    results = csv.writer(open("Results.txt" , "w")) #Creates a new file to show results.
    
    resultsList = []
    
    here is the complete data and all
    
    
    for results in resulsList:
    results.writeline(result)
    
    results.close()
    emails.close()
    

Now...i need to to save all the data which is stored in results.txt in CSV
format.

Please provide your feedback for this. thanks.


Answer: You could use numpy
[`genfromtxt`](http://docs.scipy.org/doc/numpy/reference/generated/numpy.genfromtxt.html)
and
[`savetxt`](http://docs.scipy.org/doc/numpy/reference/generated/numpy.savetxt.html):

    
    
    import numpy as np
    np.savetxt('results.csv', np.genfromtxt(file,delimiter='',dtype=None),delimiter=',')
    

Note you must set the appropriate delimiter in `genfromtxt`

