Python:某些Unicode字符无法正确显示 [英] Python: Certain unicode characters do not display correctly

查看:226
本文介绍了Python:某些Unicode字符无法正确显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试设置GUI元素的标签以使用Python显示希腊字母.

I am trying to set the label of a GUI-element to display a greek letter with Python.

str(u'\u0054'.encode('utf8')) 将正确产生Unicode字符'T',因为它的Unicode编号为0054.

str(u'\u0054'.encode('utf8')) will correctly produce the unicode character 'T', as its unicode number is 0054.

写作 str(u'\u03B6'.encode('utf8')) 不会显示希腊字母小zeta,而是显示.

Writing str(u'\u03B6'.encode('utf8')) will not display the Greek letter small zeta but this thing instead.

我尝试写作 str(u'\uceb6'.encode('utf8'))也是如此(ceb6是我想要的字符的utf-8编码),但是有一个类似的,看起来很奇怪的字符,肯定不是希腊字母zeta.

I tried writing str(u'\uceb6'.encode('utf8')) as well (ceb6 is the utf-8 encoding of the character I want), but got a similar, strange looking character that certainly wasn't the Greek letter zeta.

根据网站,该字符以常见字体提供

According to this site the character is available in common fonts.

GUI工具包可能使用了奇怪的字体吗?我正在使用FOX工具包.

Might it be that the GUI-toolkit uses a strange font? I am using the FOX toolkit.

感谢您的帮助.

我专门尝试创建一个文本标签FXLabel(parent, string),在其中提供字符串str(u'\u03B6'.encode('utf8')).如前所述,为字符串提供大写字母t的unicode号将产生预期的标签.

I am specifically trying to create a text label FXLabel(parent, string) where i supply the string str(u'\u03B6'.encode('utf8')). And as mentioned, supplying the string with the unicode number of capital t will produce the expected label.

推荐答案

您的输出编码错误.确保为UTF-8输出正确配置了终端.

Your output encoding is wrong. Make sure your terminal is correctly configured for UTF-8 output.

如果我正确解释了您的(相当泥泞的)图像,则CE B6显示为 与许多常见的西方 8位编码.

If I interpret your (rather muddy) image correctly, CE B6 is being displayed as Î‎¶‎ which is consistent with any one of a number of common Western 8-bit encodings.

这篇关于Python:某些Unicode字符无法正确显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆