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

Brian Granger ellisonbg at gmail.com
Thu Dec 5 17:34:50 EST 2013


Example is in this notebook:

http://nbviewer.ipython.org/github/ipython/ipython/blob/master/examples/notebooks/Custom%20Display%20Logic.ipynb

On Thu, Dec 5, 2013 at 2:16 PM, Jacob Vanderplas
<jakevdp at cs.washington.edu> wrote:
> 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
>
> _______________________________________________
> IPython-dev mailing list
> IPython-dev at scipy.org
> http://mail.scipy.org/mailman/listinfo/ipython-dev
>



-- 
Brian E. Granger
Cal Poly State University, San Luis Obispo
bgranger at calpoly.edu and ellisonbg at gmail.com



More information about the IPython-dev mailing list