transformation \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() and json.dump() There is a parameter ensure_ascii The default is True, Change it to False You don't encode Chinese characters into \uxxxx 了

References:

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

convert \uXXXX String to Unicode Characters in Python3.x More articles about

  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. 【 original 】 utilize typeface Realize the call and display of different fonts String Convert to Unicode

    Recent work , Just write a little demo demo from assets In the use of typeface Call different Fonts , And in editText It shows 1.layout Created in activity_main.xml file The layout code is as follows ...

  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

    Yesterday for the first time for their own windows mobile Programming CAB Installation package , But in the generation process , But there is such a problem : Compile the complete -- 0 A mistake ,0 A warning time -> G:\WindowsMobil ...

  7. pywinauto: Encountered while importing "TypeError: LoadLibrary() argument 1 must be string, not unicode"

    pywinauto: Encountered while importing "TypeError: LoadLibrary() argument 1 must be string, not unicode" Inquiry , notice ...

  8. Convert.ToInt32(string '000000003') Turned into 3

    Convert.ToInt32(string '000000003') Turned into 3 But what we need to use when querying is string there convert.toint32 It's bad , Not all the time c ...

  9. CString and string stay unicode And non unicode The mutual transformation under the background ( turn )

    The original is translated from http://blog.csdn.net/u014303844/article/details/51397556 CString and string stay unicode And non unicode The mutual transformation under the background ...

Random recommendation

  1. LoadRunner Common function analysis

    LoadRunner Common function analysis ?%Ze\N%?~"_J}.t051Testing Software test network ;FQ X%L|GO+R Web user Action51Testing Software test network b,Q8iO w1j ...

  2. perl /m

    <pre name="code" class="html">[root@backoffice01 ~]# cat a1.pl my $_=" ...

  3. javascript The realization of snake eating

    <html> <head> <style> body { background:#444; } .rect { border:1px solid #94F; wid ...

  4. JQuery actual combat —— Page progress bar effect

    This morning, I visited Ruan Yifeng Dashen's blog  ECMAScript 6 introduction   I see a progress bar at the top of the page to show the current browsing progress , Pictured : The top progress bar will adjust its width according to the current page height , It's a real fight , Visual use animated Method realization . below ...

  5. Docker Learning notes - Docker Remote access to

    Learning content : Configure remote access for clients and daemons Server configuration -H Options : Make the server support remote access Client side usage -H Options : Make the client access the remote server The local environment DOCKER_HOST Set the default server address for client access accurate ...

  6. Free test _ Soft test foundation _005 &lt; The work content of testers &gt;

    Next chapter : It's clear _ The responsibilities of the tester , That's everything What are the specific work contents of testing activities ? Q1: How to understand the work content of test engineer ? A1:SX Point of view : Integration How can the Internet industry reach today , in every particular IT The job responsibilities of the profession ...

  7. vue Click in a row 3 And the time interval is not more than 3 second , Only show div( What was hidden at first )

    num:0,// Number of hits timer0:'',// The time of the first click timer4:'',// The time of the fourth click centerDialogVisible: false // continuity 4 Click once to display the modal box change ...

  8. ComponentOne 2017 V1 Release

    Just after the celebration Visual Studio20 After the anniversary , We welcome ComponentOne 2017 The first major version of . ComponentOne Studio And Visual Studio 2017 Cooperation and development ...

  9. oc Class instantiation and method call in

    We talked about that in the last one oop And the creation of classes , Let's review the focus of the previous article class object example Method Interface In this article, we will implement class instantiation , Call common parameters and methods in a class : Class is implemented in .m In file , Here is the implementation code : // // HuiT ...

  10. JS in map, filter, some, every, forEach, for in, for of Usage Summary

    Reprinted from :http://blog.csdn.net/gis_swb/article/details/52297343 1.map There is a return value , Returns a new array , Each element is called func Result . let ...