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