python3对于编码的调整
python2默认的编码是ascii,python没办法处理非ascii编码的,此时需要自己设置将python的默认编码,一般设置为utf8的编码格式。 import sys reload(sys) sys.setdefaultencoding('utf8') 这样,转换之后默认编码就改为utf8了。 Python3.x中已经修改了编码的方式,明确了str和byte的区分,不需要使用这个转换了。 Python3.x中sys没有setdefaultencoding了,因为不需要。 python3 默认的编码为unicode UTF-8(8-bit Unicode Transformation Format)是一种针对Unicode的可变长度字符编码,又称万国码。 UTF-8用1到6个字节编码Unicode字符。 decode的作用是将其他编码的字符串转换成unicode编码,如str1.decode('gb2312'),表示将gb2312编码的字符串str1转换成unicode编码。 bytes.decode(encoding="utf-8", errors="strict") enco...