且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

使用Python删除或删除CSV文件中的最后一列

更新时间:2022-10-21 07:50:36

Use the csv module. When writing out a row, use row[:-1] to chop off the last item:

import csv

with open(filename,"r") as fin:
    with open(outname,"w") as fout:
        writer=csv.writer(fout)
        for row in csv.reader(fin):
            writer.writerow(row[:-1])