由python写出的CSV在Excel中完全空白

时间:2013-06-21 19:59:02

标签: python excel csv

我有一个简单的dict,我正在写一个csv文件,当我在服务器上查看它时看起来很好,但在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])

感谢您的帮助!

以下是我在文件中看到的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.

谢谢!

2 个答案:

答案 0 :(得分:2)

感谢您的帮助!这是用户错误,但回答您的询问帮助我抓住了自己。在关闭它之前,我正在将文件发送到某个地方。咄...

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()

谢谢!

答案 1 :(得分:0)

如果你的代码是

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

没有什么可写的,所以文件是空的

quoting = csv.QUOTE_NONE应该不应该使用