python:'ascii' codec can't encode character

python默认的编码是ascii,当程序中出现非ascii编码时,python的处理常常会报这样的错,python没办法处理非ascii编码的,

此时需要自己设置python的默认编码,一般设置为utf8的编码格式。

cat myutf8.py #添加如下内容,设置编码为utf8
# encoding=utf8 
import sys

reload(sys) 
sys.setdefaultencoding('utf8')

posted @ 2017-11-14 23:28  littlevigra  阅读(620)  评论(0编辑  收藏  举报