环境:centos6.5,python 2.6

源码文档使用utf-8

#!/usr/bin/python  
# -*- coding: UTF-8 -*-

字符串默认用utf-8(不用在前面加u了)

import sys

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

python内部语言环境改为utf-8

(这个前提是将系统的locale改为zh_CN.UTF-8)

import locale

language_code, encoding = locale.getdefaultlocale()
locale.setlocale(locale.LC_ALL, '%s.%s' % (language_code, encoding))

这三方面都配置了,应该可以应付大部分python编码的问题了

over

相关文章:

  • 2021-07-17
  • 2022-12-23
  • 2021-04-17
  • 2021-08-21
  • 2021-10-12
  • 2021-10-17
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-07-21
  • 2021-08-26
  • 2021-08-05
  • 2022-12-23
相关资源
相似解决方案