Windows 8.1中的python 3.4编码 [英] python 3.4 encoding in windows 8.1
问题描述
我使用了本文档中提到的脚本问题,检查编码:
import sys, locale, os
print(sys.stdout.encoding)
print(sys.stdout.isatty())
print(locale.getpreferredencoding())
print(sys.getfilesystemencoding())
print(os.environ["PYTHONIOENCODING"])
print(chr(246), chr(9786), chr(9787))
然后我获得了(python 3.4,Windows 8.1):
and I obtain (python 3.4, windows 8.1):
windows-1252
False
cp1252
mbcs
windows-1252
ö Traceback (most recent call last):
File "C:/Users/.../UTF8-comprovacio.py", line 8, in <module>
print(chr(246), chr(9786), chr(9787))
File "C:\Python34\lib\encodings\cp1252.py", line 19, in encode
return codecs.charmap_encode(input,self.errors,encoding_table)[0]
UnicodeEncodeError: 'charmap' codec can't encode character '\u263a' in position 0: character maps to <undefined>
我正在尝试更改Windows 8.1编码(例如,添加一个名为utf8值的"PYTHONIOENCODING"环境变量),但结果始终相同.如何在Windows 8.1中更改PYTHONIOENCODING的编码和值?(实际上,我有一台也装有Windows 8.1的计算机,它显示了正确的值utf-8,但我不知道为什么)
I'm trying to change windows 8.1 encoding (e.g. I add an environment variable called "PYTHONIOENCODING" vith utf8 value) but the result is always the same. How can I change the encoding and the value of PYTHONIOENCODING in Windows 8.1? (in fact, I have another computer, also with Windows 8.1, that shows the correct values, utf-8, but I don't know why)
推荐答案
I had the same problem last week... I ended up just changing in IDE. Don't know your IDE, but if PyCharm, starting from the menu bar: File -> Settings... -> Editor -> File Encodings, then set: "IDE Encoding", "Project Encoding" and "Default encoding for properties files" ALL to UTF-8 and she now works like a charm.
也许您有类似的选择.
这篇关于Windows 8.1中的python 3.4编码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!