python 请问怎么在txt文件中读取特殊的字符?

比如1.txt中是这个 の⊙﹏⊙b汗o(>﹏<)o
代码
a = open ('1.txt')
print(a.readlines())
返回错误
UnicodeDecodeError: 'gbk' codec can't decode bytes in position 24-25: illegal multibyte sequence
txt文件是按utf-8保存的。。感觉没有什么问题呢 求教解决办法

import codecs

with codecs.open('1.txt', 'r', 'utf-8') as handle:
for ln in handles:
print ln.encode('gbk').strip()
温馨提示:答案为网友推荐,仅供参考
第1个回答  2012-08-29
字符编码不正确,重建一个试试
相似回答