加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Linux > 正文

linux : 各个发行版中修改python27默认编码为utf-8

发布时间:2020-12-14 00:42:42 所属栏目:Linux 来源:网络整理
导读:? 在下面目录中新增文件:sitecustomize.py 内容为 # coding=utf-8 import sysreload(sys)sys.setdefaultencoding( ‘ utf8 ‘ ) 各个发行版放置位置: ? RedHat: /usr/local/python27/lib/python2.7/site-packages/ ? Ubuntu /usr/lib/python2.7 ? 其他发行

?

在下面目录中新增文件:sitecustomize.py

内容为

#coding=utf-8
import sys

reload(sys)
sys.setdefaultencoding(utf8)

各个发行版放置位置:

?

RedHat:

/usr/local/python27/lib/python2.7/site-packages/

?

Ubuntu

/usr/lib/python2.7

?

其他发行版

/usr/local/lib/python.27/site-packages

?

测试一下:使用sys.getdefaultencoding()测试,看返回是不是utf8

[[email?protected] site-packages]# python
Python 2.7.14 (default,Sep  2 2019,14:26:39)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-23)] on linux2
Type "help","copyright","credits" or "license" for more information.
>>> import sys
>>> sys.getdefaultencoding()
utf8
>>>

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读