I am working for a company that uses the Python programming language version 3.1 as a causal work now. And I ve encountered this problem: how to print out some encoded Asian characters(Chinese, Japanese, Korean) on command prompt?
Done a bit research and tried, but got no luck:
import sys
import codecs
print(sys.getdefaultencoding()) # prints out UTF-8
fileObj = codecs.open("test.txt", "r", "eucgb2312_cn")
content = fileObj.read()
print(content)
It is the last line that would cause this error:
C:Documents and SettingsMichael MaoDesktop>test.py
utf-8
Traceback (most recent call last):
File "C:Documents and SettingsMichael MaoDesktop est.py", line 6, in <module>
print(u)
File "C: oolsPython31libencodingscp437.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 >
I cannot change the default encoding from UTF-8 to anything else, so I reckon that is the problem preventing the output from being rendered correctly.
Can anyone help me out in this? Thanks a lot in advance!