Python 打印 unicode 不显示正确的符号

标签 python ubuntu python-unicode

我使用的是 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'

最佳答案

终端未正确破译您的输入。这不是 Python 问题。

为了证明这一点,使用 unicode 表示:

myunicode = u'\u0430\u0431\u0432'
print myunicode
print myunicode.encode('utf-8')

如果这没有打印原始字符串 абв 两次,那么您需要正确配置您的终端仿真器程序。

关于Python 打印 unicode 不显示正确的符号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11832997/

相关文章:

python - openshift 上的 Django 安装应用程序也可以在本地机器上运行

ubuntu - ubuntu 14.04 上的 dnx web 抛出 "System.Runtime.InteropServices.Marshal"异常 (1.0.0-beta8)

python - Windows 上的 Django 1.7 dumpdata 会扰乱 unicode 字符

python - Unicode 文本不打印到 Python 控制台/终端/屏幕

numpy - 类型错误 : ufunc 'subtract' did not contain a loop with signature matching types dtype ('<U1' ) dtype ('<U1' ) dtype ('<U1' )

python - 如何在弹性 beantalk 上更新 python Flask 应用程序?

jquery - 提交表单而不刷新/重定向当前页面(Python(Django)+ jQuery + Ajax)

ubuntu - 错误消息 '/usr/bin/ld: cannot find -lIL';我如何安装该库?

ubuntu - 无法浏览到 AWS Ubuntu EC2 实例

python : read a data set file