我是python中的新手。我正在尝试将数据存储在viewDidLoad()
文件中,但是当我运行程序时,我收到以下错误:
.csv
我的代码在这里:
Name: Msc Id: A100
Traceback (most recent call last):
File "./python.py", line 29, in <module>
obj.writeInCsvFile()
File "./python.py", line 24, in writeInCsvFile
fp.write(column)
ValueError: I/O operation on closed file
有人帮助我。提前谢谢。
答案 0 :(得分:3)
您的for
循环未缩进with
块内。像这样缩进它们:
def writeInCsvFile(self):
with open("file.csv", "wb") as fp:
wr = csv.writer(fp)
data = [["Msc", "Ijp"], ["10", "20"], ["50", "60"]]
for row in data:
for column in row:
fp.write(column)
fp.write("\t")