首页 > 解决方案 > display unicode in Html Widget of iPyWidgets

问题描述

I want to show Unicode text (Persian text) in Jupiter. Currently, I use from HTML widget to show the text likes the following:

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

But, I've gotten the following error:

TraitError: Could not decode '\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' for unicode trait 'value' of a HTML instance.

Anyhow, when print the title the result would be in Persian. What supposed to resolve the issue?

I should have mentioned that encode("utf-8") does not work properly, as I want to show the Unicode text!

标签: pythonpython-2.7unicodejupyteripywidgets

解决方案


A simple solution which I found is using decode("utf-8"):

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

推荐阅读