python - UnicodeDecodeError 读取 CSV 中的字符串

标签 python unicode csv

我在读取 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() 生成器.

关于python - UnicodeDecodeError 读取 CSV 中的字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4923929/

相关文章:

python - 将多列合并为一列 pandas

python - 使用 Python 实现 WebDriverWait 时出现问题 - InvalidArgumentException

python - 在Python中获取DNS搜索后缀

r - 使用 unicode 字符作为形状

ruby-on-rails - 数据被覆盖而不是附加到 CSV

python - 返回属性错误 : 'int' object has no attribute 'encode'

r - 在 R 中需要一种有效的方法将彩色 utf-8 表情符号字符转换为其默认皮肤

c# - 如何在 C# 中将一个 Unicode 字符串拆分为多个 Unicode 字符?

powershell - 对导入 CSV 的限制?

python - Scrapy 管道以正确的格式导出 csv 文件