Lots of things must align to print characters properly:
- What encoding is the script saved in?
- Do you have a
# coding: xxxx
statement in your script, where xxxx matches the encoding the file is saved in?
- Does your output terminal support your encoding?
import sys; print sys.stdout.encoding
a. If not, can you change the console encoding? (chcp
command on Windows)
- Does the font you are using support the characters?
Saving the script in UTF-8, this works in both PythonWin and IDLE.
# coding: utf-8
jap_word1 = u'中山'
jap_word2 = u'小倉'
print jap_word1
print jap_word2
Interestingly, I got your results with the .encode('utf-8')
added to both prints in IDLE, but it worked correctly in Pythonwin, whose default output window supports UTF-8.
Idle is a strange beast. sys.stdout.encoding
on my system produces 'cp1252'
, which doesn't support Asian characters, but it prints the first word wrong and the second one right when printing in UTF-8.