Have csv.reader tell when it is on the last line

前端 未结 7 725
误落风尘
误落风尘 2021-01-05 00:43

Apparently some csv output implementation somewhere truncates field separators from the right on the last row and only the last row in the file when the fields are null.

7条回答
  •  旧巷少年郎
    2021-01-05 01:42

    Just extend the row to the length of the header:

    for line_num, row in enumerate(reader):
        while len(row) < len(header):
            row.append('')
        ...
    

提交回复
热议问题