Python newbie here. I tried to fix the problem of writing the csv file in a larger program and decided to go back to the basics to try and find the problem.
I wrote a sample code from the Python csv read and write documentation:
import csv spamWriter = csv.writer(open('eggs.csv', 'w'), delimiter=' ', quotechar='|') spamWriter.writerow(['Spam'] * 5 + ['Baked Beans']) spamWriter.writerow(['Spam', 'Lovely Spam', 'Wonderful Spam'])
When I go to my working directory and click on "eggs.csv", the file is empty, as reported as "0 kb". The same thing happened in my larger program (empty csv files). Am I missing something completely obvious?
Thanks!
EDIT :
I just tried changing the code:
import csv csvOut=open("eggs.csv", "wb") spamWriter = csv.writer(csvOut, delimiter=' ', quotechar='|') spamWriter.writerow(['Spam'] * 5 + ['Baked Beans']) spamWriter.writerow(['Spam', 'Lovely Spam', 'Wonderful Spam']) csvOut.close()
And it worked. I am not sure why the first does not work for me.
source share