Mayur Koshti Mayur Koshti - 2 months ago 6
Python Question

Russian character decoding in python

This question only for python:

I have a city name in a string in Russian language and which is in Unicode form like,


\u041C\u043E\u0441\u043A\u0432\u0430



means


Москва



How to get original text instead of unicode characters?

Note: Do not use any import module

vz0 vz0
Answer
>>> a=u"\u041C\u043E\u0441\u043A\u0432\u0430"
>>> print a
Москва

Your string is a unicode string because each character/code point with \u is only usable from a unicode string, you should prefix the string with u. Otherwise is a regular string and each \u counts as a regular ascii character:

>>> len(a)
6
>>> b="\u041C\u043E\u0441\u043A\u0432\u0430"
>>> len(b)
36
Comments