Created
January 6, 2013 17:10
-
-
Save HQMIS/4468718 to your computer and use it in GitHub Desktop.
utf8转换为gb2312报错, 原因:gb2312对一些很生僻的中文字并不支持,比如 “囧” “苶”
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Python 2.7.2 |EPD 7.2-2 (32-bit)| (default, Sep 14 2011, 11:02:05) [MSC v.1500 32 bit (Intel)] on win32 | |
| Type "copyright", "credits" or "license()" for more information. | |
| >>> err = u'\u6c39' | |
| >>> print err | |
| 氹 | |
| >>> err.encode("gb2312") | |
| Traceback (most recent call last): | |
| File "<pyshell#2>", line 1, in <module> | |
| err.encode("gb2312") | |
| UnicodeEncodeError: 'gb2312' codec can't encode character u'\u6c39' in position 0: illegal multibyte sequence | |
| >>> err.encode("GBK") | |
| '\x9a\xeb' | |
| >>> err.encode("GB18030") | |
| '\x9a\xeb' | |
| >>> |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Python 2.7.2 (default, Jun 12 2011, 15:08:59) [MSC v.1500 32 bit (Intel)] on win32
Type "copyright", "credits" or "license()" for more information.
==== No Subprocess ====