有2种方法设置python的默认编码:
方案一:在程序中加入以下代码: 

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

 


方案二:在python的Lib\site-packages文件夹(print sys.path可查看到具体路径)下新建一个sitecustomize.py,内容为:

Python代码 
# encoding=utf8 
import sys 

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

此时重启python解释器,执行sys.getdefaultencoding(),发现编码已经被设置为utf8的了,多次重启之后,效果相同,这是因为系统在python启动的时候,自行调用该文件,设置系统的默认编码,而不需要每次都手动的加上解决代码,属于一劳永逸的解决方法

相关文章:

  • 2021-04-19
  • 2021-05-29
  • 2021-04-26
  • 2021-09-11
  • 2022-02-08
  • 2021-11-28
  • 2021-07-04
  • 2021-10-05
猜你喜欢
  • 2021-10-03
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-10-22
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案