0

我有一个简单的字典,我正在写入一个 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.

谢谢!

4

2 回答 2

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

谢谢!

于 2013-06-21T20:55:13.440 回答
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 可能不应该使用

于 2013-06-21T20:01:50.127 回答