如何将 HTML 嵌入到 IPython 输出中? [英] How to embed HTML into IPython output?
本文介绍了如何将 HTML 嵌入到 IPython 输出中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否可以将渲染的 HTML 输出嵌入到 IPython 输出中?
Is it possible to embed rendered HTML output into IPython output?
一种方法是使用
from IPython.core.display import HTML
HTML('<a href="http://example.com">link</a>')
或(IPython 多行单元别名)
or (IPython multiline cell alias)
%%html
<a href="http://example.com">link</a>
返回一个格式化的链接,但是
Which return a formatted link, but
- 此链接不会从控制台打开带有网页本身的浏览器.不过,IPython 笔记本支持诚实渲染.
- 我不知道如何在列表或
pandas
打印表格中呈现HTML()
对象.您可以执行df.to_html()
,但不能在单元格内建立链接. - 此输出在 PyCharm Python 控制台中不是交互式的(因为它不是 QT).
- This link doesn't open a browser with the webpage itself from the console. IPython notebooks support honest rendering, though.
- I'm unaware of how to render
HTML()
object within, say, a list orpandas
printed table. You can dodf.to_html()
, but without making links inside cells. - This output isn't interactive in the PyCharm Python console (because it's not QT).
如何克服这些缺点并使 IPython 输出更具交互性?
How can I overcome these shortcomings and make IPython output a bit more interactive?
推荐答案
这似乎对我有用:
from IPython.core.display import display, HTML
display(HTML('<h1>Hello, world!</h1>'))
诀窍是将它也包装在显示"中.
The trick is to wrap it in "display" as well.
这篇关于如何将 HTML 嵌入到 IPython 输出中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文