#conding:utf-8 from urllib.request import urlopen html=uropen('http://en.wikipedia.org/robots.txt') print(himl.read().decode('utf-8'))
python乱码原因
python乱码问题
常见文档读取
Python3字符串默认使用Unicode编码,所以Python3支持多语言。
以Unicode表示的str通过encode()方法可以编码为指定的bytes。
如果bytes使用ASCII编码,遇到ASCII码表没有的字符会以\x##表示,此时只用'\x##'.decode('utf-8')就可以了
乱码的原因
字符编码
#!/usr/bin/env python # encoding: utf-8 from urllib.request import urlopen req = urlopen("https://en.wikipedia.org/robots.txt") print(req.read().decode('utf-8'))
python3 乱码解决
mark