html嵌入python代码_如何将HTML嵌入到iPython输出中?

Is it possible to embed rendered HTML output into iPython output?

One way is to use

from IPython.core.display import HTML

HTML('link')

or (IPython multiline cell alias)

%%html

link

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 or pandas printed table. You can do df.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('

Hello, world!

'))

The trick is to wrap it in "display" as well.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值