我正在使用Windows 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 = "ascii" # 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 != "ascii":
# On Non-Unicode builds this will raise an AttributeError...
sys.setdefaultencoding(encoding) # Needs Python Unicode build !
答案 0 :(得分:0)
您必须在site.py
中设置另一个编码才能使用utf-8
。该文件说明了这一点:
但如果你愿意尝试,你可以改变它。
所以你可以改变
encoding = "ascii" # Default value set by _PyUnicode_Init()
到
encoding = "utf-8" # Default value set by _PyUnicode_Init()
您还可以通过启用第一个if case:
来使用Windows语言环境进行编码# Enable to support locale aware default string encodings.