python csv reader ignore blank row

前端 未结 2 717
伪装坚强ぢ
伪装坚强ぢ 2020-12-20 06:43

Im using the pythons csv reader . How can I use the following code in such a way that it ignores blank lines.

import csv
f1 = open (\"ted.csv\")
oldFile1 = c         


        
2条回答
  •  情歌与酒
    2020-12-20 07:30

    If your csv files start with a blank line, I think you should be able to skip that line with readline() before creating the csv reader:

    with open("ted.csv") as f1, open("ted2.csv") as f2, open('foo.csv', 'w') as out:
        f1.readline()
        f2.readline()
        r1, r2 = csv.reader(f1), csv.reader(f2)
    

提交回复
热议问题