简体   繁体   中英

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!

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!

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM