reading csv file without for

前端 未结 8 1691
孤街浪徒
孤街浪徒 2020-12-10 04:28

I need to read a CSV file in python.

Since for last row I receive a \'NULL byte\' error I would like to avoid using for keyword but the while.

Do you know ho

8条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-10 05:06

    Process the initial csv file and replace the Nul '\0' with blank, and then you can read it. The actual code looks like this:

    data_initial = open(csv_file, "rU")
    reader = csv.reader((line.replace('\0','') for line in data_initial))
    

    It works for me.

    And the original answer is here:csv-contain null byte

提交回复
热议问题