Python print unicode doesn't show correct symbols
-
24-06-2021 - |
Question
I am using Ubuntu 12.04 LTS. When I try something like this in terminal:
rfx@digest:/usr/share/fonts/truetype/ttf-dejavu$ echo вдлжофыдвж
вдлжофыдвж
Symbols are shown correctly. But if try to print unicode symbols using python 2.7 I get this:
>>> print u'абв'
ц│ц┌ц≈
As python shows I have utf-8 encoding by default for terminal:
>>> sys.stdout.encoding
'UTF-8'
Solution
Your input is being improperly deciphered by the terminal. This is not a Python problem.
To prove it, use the unicode representation:
myunicode = u'\u0430\u0431\u0432'
print myunicode
print myunicode.encode('utf-8')
If this does not print the original string абв
twice, then you need to configure your terminal emulator program correctly.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow