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'
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.
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.
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.
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.
>>> u'\\u0e4f\\u032f\\u0361\\u0e4f'.decode('unicode-escape')
u'\u0e4f\u032f\u0361\u0e4f'
>>> print u'\\u0e4f\\u032f\\u0361\\u0e4f'.decode('unicode-escape')
๏̯͡๏
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With