python遇到‘\u’开头的unicode编码
2015-08-04 13:01
531 查看
原文地址:http://blog.csdn.net/devil_2009/article/details/38796533
web信息中常会遇到“\u4f60\u597d”类型的字符。首先’\u‘开头就基本表明是跟unicode编码相关的,“\u”后的16进制字符串是相应汉字的utf-16编码。python里decode()和encode()为我们提供了解码和编码的方法。其中decode('unicode_escape')能将此种字符串解码为unicode字符串。
比如:
[python]
view plaincopyprint?
str1 = '\u4f60\u597d'
print str1.decode('unicode_escape')
你好
有篇讲python编码的文章比较好,http://blog.csdn.net/liuxincumt/article/details/8183391
另附两个在线工具
1、汉字转换unicode编码
http://www.bangnishouji.com/tools/chtounicode.html
2、汉字编码查询
http://xn--p8s370b.xn--fiqs8s/
web信息中常会遇到“\u4f60\u597d”类型的字符。首先’\u‘开头就基本表明是跟unicode编码相关的,“\u”后的16进制字符串是相应汉字的utf-16编码。python里decode()和encode()为我们提供了解码和编码的方法。其中decode('unicode_escape')能将此种字符串解码为unicode字符串。
比如:
[python]
view plaincopyprint?
str1 = '\u4f60\u597d'
print str1.decode('unicode_escape')
你好
有篇讲python编码的文章比较好,http://blog.csdn.net/liuxincumt/article/details/8183391
另附两个在线工具
1、汉字转换unicode编码
http://www.bangnishouji.com/tools/chtounicode.html
2、汉字编码查询
http://xn--p8s370b.xn--fiqs8s/
相关文章推荐
- python的一些总结1
- Python中return语句用法实例分析
- pickle和cPickle——python对象序列化
- python函数形参用法实例分析
- Python简明入门教程
- 将Python代码打包为jar软件的简单方法
- python函数局部变量用法实例分析
- pyhton_学习笔记0804
- python 安装easy_install和pip
- Python中通过函数对象创建全局变量
- python删除列表内容
- 从零开始学Python
- 从零开始学Python
- 解决Python传递中文参数的问题
- Python中为什么没有++和--(自增/减)
- Python中为什么没有++和--(自增/减)
- 从零开始学Python
- resolv_code
- Python时间戳的使用和相互转换
- 初学python3