我有以下代码
stream = io.StringIO(csv_file.stream.read().decode('utf-8-sig'), newline=None) // error is here
reader = csv.DictReader(stream)
list_of_entity = []
line_no, prev_len = 1, 0,
for line in reader:
在执行上述代码时,出现以下错误。
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xa0 in position 252862: invalid start byte
稍后要解决此问题,我尝试了以下方法。
stream = io.StringIO(csv_file.stream.read().decode('unicode_escape'), newline=None)
reader = csv.DictReader(stream)
list_of_entity = []
line_no, prev_len = 1, 0,
for line in reader:// error is here
当我将解码更改为
unicode_escape
时,会引发错误“_csv.Error: line contains NULL byte" at above highlighted comment line.
csv中存在空字节,我想忽略或替换它。 有人可以帮忙吗?