python csv文件打開錯誤:_csv.Error: line contains NULL byte


當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文件即可


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM