import csv
with open('v.csv', 'w') as csvfile:
cwriter = csv.writer(csvfile, delimiter=' ', quotechar='|', quoting=csv.QUOTE_MINIMAL)
for w, c in p.iteritems():
cwriter.writerow(w + c)
这里,p
是一个字典,w
和c
都是字符串。
当我试图写入文件时,它会报告错误:
ValueError : I/O operation on closed file.
帮帮我,我对python很陌生。我正在使用Python2.7.3 提前谢谢你。
相同的错误可以通过混合引起:制表符+空格。
缩进正确;
for
语句应该在with
块中:在
with
块外部,文件已关闭。相关问题 更多 >
编程相关推荐