Forums
New posts
Search forums
Members
Current visitors
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Search forums
Menu
Log in
Register
Install the app
Install
Forums
Archive
Archive
Python
Problem processing Chinese
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
[QUOTE="Peter Otten, post: 1842820"] Suppose you have a file with the following contents: '\xbc\xc7\xd5\xdf \xd0\xbb\xbd\xf0\xbb\xa2 \xa1\xa2' Then it's best to open it via codecs -- of course you have to know the encoding: u'\u8bb0\u8005 \u8c22\u91d1\u864e \u3001' This may still look strange to you but it's the unicode string's repr(). If sys.stdout.encoding is properly set on your system you can just print it: 记者 谢金虎 〠If that fails, provide the encoding explicitly: system 记者 谢金虎 〠Because now you are in unicode all further operations are performed on characters rather than bytes. Processing Chinese is no longer more difficult than any language that confines itself to plain ASCII. But if you split your text into a list [u'\u8bb0\u8005', u'\u8c22\u91d1\u864e', u'\u3001'] you probably think you are back to square one. That is because Python prints the repr() of the list items (otherwise a comma would give the impression that the list contains more items than it actually does). To get the actual characters, choose an item explicitly 记者 or convert the entire list to a string of your liking, e. g: [记者, 谢金虎, ã€] Peter [/QUOTE]
Verification
Post reply
Forums
Archive
Archive
Python
Problem processing Chinese
Top