Last active
December 10, 2015 08:08
-
-
Save HQMIS/4405267 to your computer and use it in GitHub Desktop.
Python 编码, 研究
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
| For IDLE | |
| 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. | |
| >>> import sys | |
| >>> sys.getdefaultencoding() | |
| 'ascii' | |
| >>> str_Chinese = "电源管理" | |
| >>> print "".join(["%"+str(hex(ord(x)))[2:] for x in str_Chinese.decode("gb2312").encode("utf8")]) | |
| %e7%94%b5%e6%ba%90%e7%ae%a1%e7%90%86 | |
| >>> | |
| For .py | |
| import sys | |
| print sys.getdefaultencoding() | |
| str_Chinese = "电源管理" | |
| print "".join(["%"+str(hex(ord(x)))[2:] for x in str_Chinese.decode("gb2312").encode("utf8")]) | |
| #-*-coding:utf-8-*- | |
| str_Chinese = "电源管理" | |
| print "".join(["%"+str(hex(ord(x)))[2:] for x in str_Chinese]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment