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

前端 未结 7 609
误落风尘
误落风尘 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('')
        ...
    
    0 讨论(0)
提交回复
热议问题