【问题标题】:how to display a python string as HTML in jupyter notebook如何在jupyter笔记本中将python字符串显示为HTML
【发布时间】:2016-07-16 00:30:56
【问题描述】:

在 IPython 笔记本中,我曾经能够通过使用 IPython 显示模块中的 HTML 函数将包含 html 的 python 字符串显示为实际的 html。

from IPython.display import HTML

在 jupyter notebook 中显示模块不再存在。有谁知道我在哪里可以找到 HTML 函数?

我使用 Jupyter notebook 4.1、IPython 4.0.2 和 Python 3.5.1 64 位

【问题讨论】:

  • 它还在IPython.display 中。笔记本中的代码使用的 Python 接口是 IPython 的一部分。 Jupyter 是独立于语言的部分,例如笔记本 UI 和文档格式。
  • 什么鬼!我害怕我在尝试这个时犯了一个令人尴尬的错字!非常感谢!

标签: python html python-3.x ipython jupyter-notebook


【解决方案1】:

使用函数display

def bar():
    from IPython.display import display, HTML
    chart = HTML('<h1>Hello, world!</h1>')
    # or chart = charts.plot(...)
    display(chart)

bar()

来源:http://suanfazu.com/t/jupyter-highcharts/13438/2

【讨论】:

    猜你喜欢
    • 2021-11-20
    • 2017-10-26
    • 2015-05-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-03-21
    • 2022-01-26
    • 2020-05-11
    相关资源
    最近更新 更多