Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Conversion of strings like \\uXXXX in python

Tags:

I have a string like \uXXXX (representation) and I need to convert it into unicode. I receive it from 3rd party service so python interpreter doesn't convert it and I need conversion in my code. How do I do it in Python?

>>> s
u'\\u0e4f\\u032f\\u0361\\u0e4f'
like image 490
Soid Avatar asked May 13 '10 16:05

Soid


People also ask

How do you convert string to type in Python?

In Python an integer can be converted into a string using the built-in str() function. The str() function takes in any python data type and converts it into a string.

What is string conversion Python?

To convert, or cast, a string to an integer in Python, you use the int() built-in function. The function takes in as a parameter the initial string you want to convert, and returns the integer equivalent of the value you passed.

How do I convert a string to an element in Python?

The most straightforward way is to type cast the string into a list. Tyepcasting means to directly convert from one data type to another – in this case from the string data type to the list data type. You do this by using the built-in list() function and passing the given string as the argument to the function.

How do I convert a string to 3 in Python?

We can convert numbers to strings using the str() method. We'll pass either a number or a variable into the parentheses of the method and then that numeric value will be converted into a string value.


1 Answers

>>> u'\\u0e4f\\u032f\\u0361\\u0e4f'.decode('unicode-escape')
u'\u0e4f\u032f\u0361\u0e4f'
>>> print u'\\u0e4f\\u032f\\u0361\\u0e4f'.decode('unicode-escape')
๏̯͡๏
like image 82
Ignacio Vazquez-Abrams Avatar answered Nov 05 '22 16:11

Ignacio Vazquez-Abrams