csv_writer.writerow(line)ValueError:对关闭文件的I / O操作

时间:2019-04-23 15:56:04

标签: python-3.x

import csv

with open('dataDusta.csv','r') as csv_file:
    csv_reader = csv.reader(csv_file)

    with open('new_dataDusta.csv','w') as new_file:
        csv_writer = csv.writer(new_file, delimiter = ",")

    for line in csv_reader:
        csv_writer.writerow(line)

1 个答案:

答案 0 :(得分:0)

您在new_file上进行的所有操作都必须在打开它的with open( ...之内。这包括使用csv_writer,本身就是使用new_file