Skip to main content
 首页 » 编程设计

python之为什么我的 defaultencoding ‘utf-8’ 使用 python 2.7.2

2025年05月04日11zdz8207

在Python中,默认编码存储在'unicode_default_encoding'中,我找到了所有Python源代码,有2个函数。

  1. _PyUnicode_Init()//strcpy(unicode_default_encoding, "ascii");
  2. setencoding() 在 site.py 中

所以没有人修改默认编码。那为什么我的默认编码是“utf-8”?

请您参考如下方法:

看起来 site.py 中的设置会影响默认编码。

查看 http://blog.ianbicking.org/illusive-setdefaultencoding.html

Edit site.py (in the standard library) directly. Seems like a bad idea. Though maybe I'll just delete the del sys.setdefaultencoding line... anyway, site.py might appear in other places on your computer as well (e.g., /etc/pythonX.Y/site.py).