python – 以CSV格式读取字符串的UnicodeDecodeError
发布时间:2020-12-20 11:17:02 所属栏目:Python 来源:网络整理
导读:我在阅读 python中的一些字符时遇到问题. 我有一个UTF-8格式的csv文件,我正在阅读,但是当脚本读取时: Preu??en M??nster-Kaiserslautern II 我收到此错误: Traceback (most recent call last): File "/Applications/GoogleAppEngineLauncher.app/Contents/
我在阅读
python中的一些字符时遇到问题.
我有一个UTF-8格式的csv文件,我正在阅读,但是当脚本读取时: Preu??en M??nster-Kaiserslautern II 我收到此错误: Traceback (most recent call last): File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/ext/webapp/__init__.py",line 515,in __call__ handler.get(*groups) File "/Users/fermin/project/gae/cuotastats/controllers/controllers.py",line 50,in get f.name = unicode( row[1]) UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 4: ordinal not in range(128) 我尝试使用Unicode函数并将字符串转换为Unicode,但我还没有找到解决方案.我试图使用sys.setdefaultencoding(‘utf8’),但这也不起作用. 解决方法
尝试
csv module docs中描述的unicode_csv_reader()生成器.
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |