如何将HTML嵌入到iPython输出中? [英] How to embed HTML into iPython output?
本文介绍了如何将HTML嵌入到iPython输出中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否可以将呈现的HTML输出嵌入到iPython输出中? $ p> from IPython.core.display import HTML
HTML('< a href =http://example.com>链接< / a>')
或(IPython多行单元格别名)
%% html
< a href =http://example.com>连结< / a>
返回格式化的链接,但是
- 此链接不会从控制台中的网页本身打开浏览器。不过,IPython笔记本支持诚实渲染。
- 我不知道如何在列表中呈现
HTML()
对象或pandas
打印的表格。您可以执行df.to_html()
,但不会在单元格内建立链接。 这个输出在PyCharm Python控制台(因为它不是QT)。
我如何克服这些缺点并使iPython输出更具互动性?
解决方案
这似乎适用于我:
from IPython.core.display import display,HTML
pre>
display(HTML('< h1> Hello,world!< / h1>))
诀窍是将它包装在display中。
Is it possible to embed rendered HTML output into iPython output?
One way is to use
from IPython.core.display import HTML HTML('<a href="http://example.com">link</a>')
or (IPython multiline cell alias)
%%html <a href="http://example.com">link</a>
Which return a formatted link, but
- This link doesn't open a browser with the webpage itself from the console. IPython notebooks support honest rendering, though.
- I'm unaware about 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).
How can I overcome thes shortcomings and make iPython output a bit more interactive?
解决方案This seems to work for me:
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屋!
查看全文