Python read CSV file prompt “line contains null byte” error

Open source software supply chain lighting plan, waiting for you>>>

When Python reads a file, it appears_ When CSV. Error: line contains null byte

# -*- coding:utf-8 -*-

import csv

with open(r'E:\abc\web_test\userinfo.csv','rb') as f:
    reader = csv.reader(f)
    rows = [row for row in reader]
    print rows

Error:

D:\Python27\python.exe E:/abc/loop_reader.py
Traceback (most recent call last):
  File "E:/abc/web_test/loop_reader.py", line 7, in <module>
    rows = [row for row in reader]
_csv.Error: line contains NULL byte

Process finished with exit code 1

The error prompt is:_ csv.Error: line contains NULL byte

CSV error, line contains empty bytes

Reason: it is usually because the extension is XLS or xlsx when saving, and changing it to a CSV file is usually a rename

Solution: save it as a. CSV file

Similar Posts: