关闭fi上的I/O操作错误

2024-04-27 04:48:10 发布

您现在位置:Python中文网/ 问答频道 /正文

谁能告诉我这个代码有什么问题吗。你知道吗

import csv 
import glob

with open("1.csv") as sample:
     reader = csv.reader(sample)
     header = 'Name', 'ID', 'Marks'

with open("out1.csv", "wb") as out1:
     writer = csv.writer(out1)
     writer.writerow(header)


for path in glob.glob("out.csv"):
     if path == "out1.csv": continue
     with open(path) as fh:
           reader = csv.reader(fh)
           for row in reader:
               if row[0] == 'Name' and row[1] == 'ID':
                    writer.writerow(row)

对关闭的文件执行I/O操作时出错 编写器.writerow(世界其他地区) ValueError:对关闭的文件执行I/O操作


Tags: csvsamplepathnameimportaswithopen