|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
import csv
with open('C:\\Users\\Lenovo\\Desktop\\测试1.csv','r') as file:
reader=csv.reader(file)
for k in reader:
print(reader)
这是代码
我不知道为什么不能添加截图
Traceback (most recent call last):
File "C:\Users\Lenovo\Desktop\hhh.py", line 4, in <module>
for k in reader:
UnicodeDecodeError: 'gbk' codec can't decode byte 0xbf in position 2: illegal multibyte sequence
这是错误原因
这里报错的原因是因为文件的编码和 Python 程序打开的编码不一致,导致解码错误
在 open 里面加入 encoding = "utf-8" 参数即可,参考代码:
- import csv
- with open('C:\\Users\\Lenovo\\Desktop\\测试1.csv','r', encoding="utf-8") as file:
- reader=csv.reader(file)
- for k in reader:
- print(reader)
复制代码
|
|