Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python decode "\u041b" string [duplicate]

Tags:

python

unicode

I have unicode string, i'm sure that it's UTF-8, but I can't decode it. The string is '\u041b\u0435\u0433\u043a\u043e\u0432\u044b\u0435'. How to decode it?

like image 407
artem Avatar asked Apr 17 '13 11:04

artem


1 Answers

You can use aString.decode('unicode_escape'), it convert a unicode-format string to unicode object

>>> u'\u041b\u0435\u0433\u043a\u043e\u0432\u044b\u0435'
u'\u041b\u0435\u0433\u043a\u043e\u0432\u044b\u0435'
>>> '\u041b\u0435\u0433\u043a\u043e\u0432\u044b\u0435'.decode('unicode_escape')
u'\u041b\u0435\u0433\u043a\u043e\u0432\u044b\u0435'
>>>

In your case

>>> print '\u041b\u0435\u0433\u043a\u043e\u0432\u044b\u0435'.decode('unicode_escape')
Легковые
>>> 
like image 175
muzuiget Avatar answered Nov 15 '22 08:11

muzuiget