當python讀取文件出現_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
報錯:
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
錯誤提示為:_csv.Error: line contains NULL byte
翻譯為:CSV錯誤,行包含空字節
原因:通常是因為保存時擴展名為xls或xlsx,而將其改為csv文件通常是重命名
解決方法:把它另存為.csv文件即可