Python如何查看汉字的unicode码
打开Python解释器,
- Python code
>>> u'语言'u'\u8bed\u8a00'
现有:
- Python code
str = "我爱派森" #u'str出错
我想打印出str的unicode值,而且形式要是\uXXXX这种, 比如上面的str在终端中输出的不是原话, 而是
\u6211\u7231\u6d3e\u68ee
怎么做?
[解决办法]
我的 linux 用的是 UTF-8 编码格式,你可以按照你系统的情况改:
- Python code
Python 2.7.3 (default, Apr 20 2012, 22:39:59) [GCC 4.6.3] on linux2Type "copyright", "credits" or "license()" for more information.==== No Subprocess ====>>> str = "我爱派森">>> str.decode('UTF-8')u'\u6211\u7231\u6d3e\u68ee'>>>