Christina
Christina

Reputation: 1439

CSV written out by python is completely blank in Excel

I have a simple dict that I'm writing to a csv file and it looks fine when I view it on the server, but it is completely blank in excel.

csvOutput = {'http://www.test.com/': 'This source is currently in the system.', 'http://test.com/': 'This source is not currently in the system.', 'http://www.test.com/': 'This source is currently in the system.'}

writer = csv.writer(open(csvFileName, 'wb'), quoting=csv.QUOTE_NONE, dialect='excel')
for key, value in csvOutput.items():
    writer.writerow([key, value])

Thanks for your help!

And here is what I see in the file with vim:

http://www.test.com/,This source is currently in the system.
http://test.com/,This source is not currently in the system.  
http://www.test.com/,This source is currently in the system.

Thanks!

Upvotes: 0

Views: 96

Answers (2)

Christina
Christina

Reputation: 1439

Thanks for all your help! It was user error, but answering your inquiries helped me catch myself. I was sending the file somewhere before I closed it. Duh...

for key, value in csvOutput.items():
    writer.writerow([key, value])

f1.close() # I hadn't closed it here.

f2 = open(csvFileName)
jira.add_attachment(issueKey, f)
f2.close()

Thanks!

Upvotes: 2

Xavier Combelle
Xavier Combelle

Reputation: 11195

If your code is

csvOutput={}
writer = csv.writer(open(csvFileName, 'wb'), quoting=csv.QUOTE_NONE, dialect='excel')
for key, value in csvOutput.items():
    writer.writerow([key, value])

there is nothing to write so the file is empty

quoting=csv.QUOTE_NONE should probably not used

Upvotes: 0

Related Questions