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

相关文章:

  • 2021-09-11
  • 2021-12-07
  • 2022-12-23
  • 2021-11-30
  • 2021-04-08
  • 2022-12-23
  • 2021-08-24
  • 2021-07-05
猜你喜欢
  • 2022-12-23
  • 2021-07-13
  • 2021-12-26
  • 2022-12-23
  • 2021-12-18
  • 2022-01-28
相关资源
相似解决方案