python open出来的中文使用findall后乱码
張葒兵 2017-05-22 08:39:18 我的py文件中设置了utf-8,setting中也设置了utf-8,text.txt文件的编码格式也是utf-8,为什么f.read()出来显示中文不乱码,使用findall()方法后反而乱码呢,求大神指导
# encoding:utf-8
import re
f = open('text.txt','r')
text = f.read()
f.close()
print text
content = re.findall('<title>(.*?)</title>',text)
print content
-----------------------------------------------------输出的结果--------------------------------------------------------
C:\Python27\python.exe G:/workspace/leanPython/readFile.py
<html>
<title>我的第一个Python程序</title>
</html>
['\xe6\x88\x91\xe7\x9a\x84\xe7\xac\xac\xe4\xb8\x80\xe4\xb8\xaaPython\xe7\xa8\x8b\xe5\xba\x8f']