无法在python中读取csv文件

时间:2019-09-24 19:42:35

标签: python csv

我之前已经在python中多次打开和读取csv文件,但是由于某种原因,这次我一直收到此错误。

错误:

File "C:\Program Files\Python37\lib\encodings\cp1250.py", line 23, in decode
    return codecs.charmap_decode(input,self.errors,decoding_table)[0]
UnicodeDecodeError: 'charmap' codec can't decode byte 0x90 in position 22: character maps to <undefined>

我的代码:

with open("databa.csv", 'r') as fp:
    for line in fp:
        print(line)

我已经尝试过重命名文件,将格式设置为'UTF8'或忽略错误(“ databa.csv”,“ r”,errors ='ignore“),但没有一个起作用

with open(r"databa.csv", 'rb') as fp: 
with open("databa.csv", 'r', buffering=0) as fp: 
with open("databa.csv", errors="ignore") as fp: 
with open("databa.csv",encoding='utf8', errors="ignore") as fp: 
with open("databa.csv",encoding='utf8', "r") as fp: 
with open("databa.csv", encoding='utf8', "r") as fp

1 个答案:

答案 0 :(得分:1)

我运行了您提供的示例,它运行正常,没有任何问题:

enter image description here

提供的样本数据:

enter image description here

输出:

enter image description here