【发布时间】:2016-05-18 16:23:52
【问题描述】:
我在读取 CSV 文件时遇到问题。我的 Django 应用 (Python 2) 使用编码 utf-8 并尝试读取 latin1 CSV 文件。
# Open file
file = open(file_name)
content = file.readlines()
# content[0]
'\xff\xfeR\x00a\x00f\x00a\x00e\x00l\x00 \x00V\x00i\x00v\x00o\x00 \x00P\x00R\x00\n'
# content[0] is <type 'str'>
# I need real text: u'Rafael Vivo PR'
我尝试了一些编码/解码功能,但没有成功。
【问题讨论】:
-
这看起来很像带有 BOM 的 UTF-16。