python2.7中在windows下默认使用ascii编码模式,如果在编写程序中使用了unicode,程序运
行时便会报错,其实只需要修改python2.7安装目录下的site.py文件中的
行时便会报错,其实只需要修改python2.7安装目录下的site.py文件中的
def setencoding():
"""Set the string encoding used by the Unicode implementation. The
default is 'ascii', but if you're willing to experiment, you can
change this."""
encoding = "<span style="color:#FF0000;">utf-8</span>" # Default value set by _PyUnicode_Init()
if 0:
# Enable to support locale aware default string encodings.
import locale
loc = locale.getdefaultlocale()
if loc[1]:
encoding = loc[1]
if 0:
# Enable to switch off string to Unicode coercion and implicit
# Unicode to string conversion.
encoding = "undefined"
if encoding != "<span style="color:#FF0000;">utf-8</span>":
# On Non-Unicode builds this will raise an AttributeError...
sys.setdefaultencoding(encoding) # Needs Python Unicode build !