[IPython-dev] Notebook: grabbing HTML for an arbitrary object

Jacob Vanderplas jakevdp at cs.washington.edu
Thu Dec 5 17:16:26 EST 2013


Hi,
I'm hacking on the notebook a bit and ran into something I don't know how
to do.

I know that for user-defined objects, one can define a ``_repr_html_()``
method, and then calling ``display()`` in the notebook will use this
function to create an html representation.

But how can I get the HTML representation for a built-in object which does
not define ``_repr_html_``?

To be more concrete, I want a function ``get_html_rep()`` so that the
following two cells show the same result in the notebook, for an arbitrary
object ``myobj``:

In [1]:
from IPython.display import HTML
html = get_html_rep(myobj)
HTML(html)

In [2]:
from IPython.display import display
display(myobj)

Does a function like this exist?  Can it be easily created? Any help would
be appreciated.  Thanks!
   Jake
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/ipython-dev/attachments/20131205/adf6b4ca/attachment.html>


More information about the IPython-dev mailing list