转换\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. 【hihoCoder】1041. 国庆出游

    问题:详见http://hihocoder.com/problemset/problem/1041 有n个城市,城市编号为1-n,城市间有n-1条路(所以,城市路网是一棵树).给定一个序列S,要求判断 ...

  2. XML 中对当前时间的引用

    current_date 而不是 date 然而,在attrs 和 readonly中并不适用.

  3. Server Tomcat v7.0 Server at localhost was unable to start within 45 seconds 解决方法

    Server Tomcat v6.0 Server at localhost was unable to start within 45 seconds. If the server requires ...

  4. 全选,不选,反选 jquery

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  5. 利用Columnal网格系统快速搭建网站的基本布局结构

    1.下面是一些对响应式设计提供了不同程度支持的CSS框架: (1)Semantic(http://semantic.gs); (2)Skeleton(http://getskeleton.com); ...

  6. Ajax 无刷新上传文件插件 uploadify 的使用

    在表单中无法直接使用 Ajax 上传文件,解决的思路可以是使用插件无刷新地上传文件,返回文件上传后的地址,然后把该地址作为 Ajax 的参数传递给服务器端进行数据库处理.可以使用 uploadify ...

  7. GDC2016 【全境封锁】的全局照明技术

    现在全力支持公司的GAD平台了,很多的内部分享也可以放出来 http://gad.qq.com/article/detail/7159232

  8. C 到C++的升级

    C++所有的变量都可以在需要使用时再定义. C语言中的变量都必须在作用域开始的位置定义. register 关键字请求编译器将局部变量存储于寄存器中 在C语言无法获取register 变量的地址 在C ...

  9. Flink - metrics

      Metrics是以MetricsGroup来组织的 MetricGroup MetricGroup 这就是个metric容器,里面可以放subGroup,或者各种metric 所以主要的接口就是注 ...

  10. ajax同步、异步执行简单理解与证明

    此理解范例代码来自前几篇随笔! 首先我们来先了解下AJAX: Ajax:全称“Asynchronous Javascript and XML”(异步Javascript和XML),他是由Javascr ...