Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python Unicode string stored as '\u84b8\u6c7d\u5730' in file, how to convert it back to Unicode?

Tags:

python

unicode

Some Unicode data is stored in file as '\u84b8\u6c7d\u5730' without any encoding.

Is there a way to covert them back in Python?

like image 754
lucemia Avatar asked Jun 19 '12 04:06

lucemia


People also ask

How do you change a Unicode to a string in Python?

To convert Python Unicode to string, use the unicodedata. normalize() function. The Unicode standard defines various normalization forms of a Unicode string, based on canonical equivalence and compatibility equivalence.

How do I remove Unicode from a string in Python?

In python, to remove Unicode ” u “ character from string then, we can use the replace() method to remove the Unicode ” u ” from the string. After writing the above code (python remove Unicode ” u ” from a string), Ones you will print “ string_unicode ” then the output will appear as a “ Python is easy. ”.

How do I convert Unicode to letter in Python?

In Python, the built-in functions chr() and ord() are used to convert between Unicode code points and characters. A character can also be represented by writing a hexadecimal Unicode code point with \x , \u , or \U in a string literal.


1 Answers

>>> print '\u84b8\u6c7d\u5730'.decode('unicode-escape')
蒸汽地
like image 195
Ignacio Vazquez-Abrams Avatar answered Sep 27 '22 22:09

Ignacio Vazquez-Abrams