4 ms·
Pretty-printing of data structures in a human-readable format.
by chrissnell 9y ago
Pretty-printing of data structures in a human-readable format.
- deleted 9y ago[deleted]
- yorwba 9y agoI think Jupyter has the right idea here with various kinds of repr-alternatives that can render html or images directly into the notebook. http://ipython.readthedocs.io/en/stable/config/integrating.html?highlight=repr#rich-display http://ipython.readthedocs.io/en/stable/config/integrating.h...
- junke 9y agoThis is the kind of use cases where multiple dispatch is useful.
- yorwba 9y agoHow so? I feel like single dispatch (as in Python) is already enough.
- junke 9y agoIf you write a custom _repr_html_, you are likely to assemble subparts by recursively calling _repr_html_ on sub-elements (thanks to open recursion). If you have an object B which inherits from A, you can specialize on B, or use the existing method for A. However, you cannot specializes the "html" part with inheritance. Say for example that you want to define a slightly different _repr_html_ method depending on the context (maybe you target the subset of HTML that works correctly in emails) or if you want to render "latex" with custom "tikz" macros instead of using matplotlib. With multiple dispatch, you can specialize on the target too, which means you can specialize wherever required or fall back to a generic behavior if not.