我现在为一家使用 Python 编程语言 3.1 版作为因果工作的公司工作。我遇到了这个问题:如何在命令提示符下打印出一些编码的亚洲字符(中文、日文、韩文)?
做了一些研究并尝试了,但没有运气:
import sys
import codecs
print(sys.getdefaultencoding()) # prints out UTF-8
fileObj = codecs.open("test.txt", "r", "eucgb2312_cn")
content = fileObj.read()
print(content)
这是导致此错误的最后一行:
C:\Documents and Settings\Michael Mao\Desktop>test.py
utf-8
Traceback (most recent call last):
File "C:\Documents and Settings\Michael Mao\Desktop\test.py", line 6, in <module>
print(u)
File "C:\tools\Python31\lib\encodings\cp437.py", line 19, in encode
return codecs.charmap_encode(input,self.errors,encoding_map)[0]
UnicodeEncodeError: 'charmap' codec can't encode character '\u5377' in position 3: character maps to < undefined >
我无法将默认编码从 UTF-8 更改为其他任何内容,因此我认为这是阻止正确呈现输出的问题。
谁能帮我解决这个问题?提前非常感谢!