Python将'\u'开头的字符串转为unicode编码
2016-07-17 22:31
302 查看
web信息中常会遇到“\u4f60\u597d”类型的字符。首先’\u‘开头就基本表明是跟unicode编码相关的,“\u”后的16进制字符串是相应汉字的utf-16编码。Python里decode()和encode()为我们提供了解码和编码的方法。其中decode('unicode_escape')能将此种字符串解码为unicode字符串。
比如:
[python] view
plain copy
print?
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/
原文链接:http://blog.csdn.net/devil_2009/article/details/38796533
比如:
[python] view
plain copy
print?
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/
原文链接:http://blog.csdn.net/devil_2009/article/details/38796533
相关文章推荐
- 学习python处理python编码问题
- Python编码时应该注意的几个情况
- 【转】python中文decode和encode转码
- python判断字符串编码——使用chardet判断字符串编码的方法
- Python中utf-8与utf-8-sig两种编码格式的区别
- Python中的str与unicode处理方法
- Python字符串编码的encode与decode
- Python爬虫时 urllib2.urlopen中文乱码
- 修改python编码
- python中编码问题
- python2 打不开中文文件
- Python编程中遇到NameError: name 'reload' is not defined 问题以及Python编码问题
- python编码问题2
- python编码问题1
- python3的编码问题
- Python chardet模块
- 一些新手经常遇到的python编码错误
- python的注释和中文编码
- Python爬取淘宝图片
- python编码问题