I was trying to conquer the Chinese encoding issue. So far the only obstacle before me is to show correctly the user typed in the raw_input()
. For example, my abstract solution about this part is like this:
#coding: utf-8
name_a = raw_input('请输入文字')
print name_a
But by this I can only show '请输入文字' correctly. If a user typed in a Chinese character in raw_input(), the print name_a will show utf-8 code point like '/xb7'
Anyhow, I've searched online, and find this code can solve my problem:
#coding: utf-8
n=raw_input(unicode('请输入文字','utf-8').encode('gbk'))
print n
It worked! But when I trying to plant it into my own code. My code can't be executed. And there was something even more weird happened. Later when I copy this code into other empty file, it can't work, too. Just a blink and the program was over (I know the feature of python under Windows environment so I added x = input()
at the end of the file). And later I deleted the original test py file which contains the second code paragraph. Now I can't execute it in any new created file now.
I'm using Python 2.7 under Windows XP environment
What happened?
And is there another way that can help me show the Chinese content the user typed into the raw_input()
?
Thank you very much.