如何将HTML嵌入到iPython输出中? [英] How to embed HTML into iPython output?

查看:642
本文介绍了如何将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>

返回格式化的链接,但是


  1. 此链接不会从控制台中的网页本身打开浏览器。不过,IPython笔记本支持诚实渲染。

  2. 我不知道如何在列表中呈现 HTML()对象或 pandas 打印的表格。您可以执行 df.to_html(),但不会在单元格内建立链接。 这个输出在PyCharm Python控制台(因为它不是QT)。

我如何克服这些缺点并使iPython输出更具互动性?

解决方案

这似乎适用于我:

  from IPython.core.display import display,HTML 
display(HTML('< h1> Hello,world!< / h1>))
pre>

诀窍是将它包装在display中。

来源:http://python.6.x6.nabble.com/打印 - IPython-Notebook中的HTML-IPython-specific-prettyprint-tp5016624p5016631.html


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

  1. This link doesn't open a browser with the webpage itself from the console. IPython notebooks support honest rendering, though.
  2. I'm unaware about how to render HTML() object within, say, a list or pandas printed table. You can do df.to_html(), but without making links inside cells.
  3. 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.

Source: http://python.6.x6.nabble.com/Printing-HTML-within-IPython-Notebook-IPython-specific-prettyprint-tp5016624p5016631.html

这篇关于如何将HTML嵌入到iPython输出中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆