代码之家  ›  专栏  ›  技术社区  ›  OmG

在iPyWidgets的Html小部件中显示unicode

  •  0
  • OmG  · 技术社区  · 6 年前

    我想在Jupiter中显示Unicode文本(波斯语文本)。目前,我使用from HTML小部件显示如下文本:

    # title is unicode
    title_value = widgets.HTML(value = title)
    

    TraitError:无法为HTML实例的unicode特征“value”解码“\xd9\xbe\xda\x98\xd9\x88 405\xd9\x85\xd8\xb4\xda\xa9\xdb\x8c\xd9\x81\xd8\xb1\xd9\x88\xd8\xb4 90 91”。

    不管怎样,什么时候 print 结果的标题是波斯语。 怎么解决这个问题?

    我应该提到的 encode("utf-8") 无法正常工作,因为我想显示Unicode文本!

    1 回复  |  直到 6 年前
        1
  •  0
  •   OmG    6 年前

    我发现一个简单的解决方法是 decode("utf-8") :

    title_value = widgets.HTML(value = title.decode("utf-8"))