2014-10-19 30 views

回答

1

呼叫_repr_html_直接:

from IPython.display import display 
class Foo(object): 

    def _repr_html_(self): 
     return "<b>HTML</b>" 

display(Foo()) #display HTML in bold 
Foo()._repr_html_() # return "<b>HTML</b>" 

這隻有當對象實施_repr_*_本身。如果格式化程序在IPython上註冊了一個對象,您可以像這樣粗略訪問它:get_ipython().display_formatter.formatters['text/html'].for_type(your_object)但您只需要使用此方法的機率很小。