python2与python3编码问题

python2:  

UnicodeDecodeError: 'ascii' codec can't decode byte 0xc4 in position 33: 

解决办法:

在报错的页面添加代码: import sys 
reload(sys) 
sys.setdefaultencoding('utf8') 

python 3:

open函数可以带参数。

fp=open("index.html",encoding= 'utf-8')

原文地址:https://www.cnblogs.com/skying555/p/4447719.html