您的位置:首页 > 编程语言 > Python开发

python默认编码设置

2015-04-27 19:41 260 查看
打开python 的gui,输入

查询系统当前默认编码

默认情况下显示编码方式为ASCII

在python安装目录下的Lib/site-packages文件夹下新建sitecustomize.py,内容为

重启python,再次检查编码方式,发现已经改为utf8

sitecustomize.py is a special script; Python will try to import it on startup, so any code in it will be run automatically. As the comment mentions, it can go anywhere (as long as import can find it), but it usually goes in the site-packages directory within your Python lib directory.

setdefaultencoding function sets, well, the default encoding. This is the encoding scheme that Python will try to use whenever it needs to auto-coerce a unicode string into a regular string.

参考:

https://docs.python.org/2/library/site.html

/article/4868217.html

http://blog.chinaunix.net/uid-22183602-id-2973101.html
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: