【发布时间】:2016-04-26 22:56:05
【问题描述】:
我正在尝试对文件进行简单解析,但由于特殊字符而出现错误:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
infile = 'finance.txt'
input = open(infile)
for line in input:
if line.startswith(u'▼'):
我得到错误:
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc2 in position 1718: ordinal not in range(128)
解决方案?
【问题讨论】:
-
您也可以使用
codecs来打开带有utf-8或utf-16编码的文件
标签: python string python-2.7 encoding