8

我正在使用 Ubuntu 12.04 LTS。当我在终端尝试这样的事情时:

rfx@digest:/usr/share/fonts/truetype/ttf-dejavu$ echo вдлжофыдвж
вдлжофыдвж

符号显示正确。但是,如果尝试使用 python 2.7 打印 unicode 符号,我会得到:

>>> print u'абв'
ц│ц┌ц≈

正如 python 所示,我默认为终端使用 utf-8 编码:

>>> sys.stdout.encoding
'UTF-8'
4

1 回答 1

5

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.

于 2012-08-06T18:01:29.877 回答