为什么我无法更改我的python默认编码?

时间:2013-04-27 10:55:34

标签: python default

nano  /usr/local/lib/python2.7/site-packages/sitecustomize.py

import sys  
reload(sys)  
sys.setdefaultencoding('UTF-8')  

我完成后,

root@debian:/home/debian# python
Python 2.7.3 (default, Jan  2 2013, 16:53:07) 
[GCC 4.7.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> print sys.getdefaultencoding()
ascii

怎么回事?

1 个答案:

答案 0 :(得分:0)

您需要阅读以下内容:

  1. Why should we NOT use sys.setdefaultencoding("utf-8") in a py script?
  2. How to print UTF-8 encoded text to the console in Python < 3?
  3. 我建议您使用# -*- coding: utf-8 -*-作为.py文件的顶部。