tags:

views:

152

answers:

2

How can I get python to work with simplified Chinese text input either as strings or raw input?

A: 

Decode on input.

u = s.decode('gb2312')
Ignacio Vazquez-Abrams
input example: u = '世界您好!'still not working
JCR000
string rather: = '世界您好!'
JCR000
'gb2312' encoding and decodeing seems unavaile to my Python 2.6.5rc1 installation
JCR000
I don't know what to tell you then. It's working fine here on 2.6.2. Perhaps there's another package you need to install in order to get the codec.
Ignacio Vazquez-Abrams
I think on some Linux distros it mightn't be installed - you may need to install them from http://cjkpython.i18n.org/
David Morrissey
Reverted back to python 2.6.2 and captured input with raw_input(). That works. Probably in 2.6.5 also but I did not try it.>>s = raw_input("Insert Chinese Text Here: ")你好世界>>u'\u4f60\u597d\u4e16\u754c'>> print s>> 你好世界
JCR000
A: 

Trivial handling of Chinese characters in python 2.6.2 32 bit on windows vista 64 bit

.>> s = raw_input("Insert Chinese Text Here: ")

你好世界

.>> u'\u4f60\u597d\u4e16\u754c'

.>> print s

你好世界

.>>

JCR000