I should note that the best documentation we do have is in the display_protocol notebook in docs/examples/notebooks.<br><br><div class="gmail_quote">On Sat, Oct 22, 2011 at 11:22, MinRK <span dir="ltr"><<a href="mailto:benjaminrk@gmail.com">benjaminrk@gmail.com</a>></span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;"><br><br><div class="gmail_quote"><div><div></div><div class="h5">On Sat, Oct 22, 2011 at 10:49, Warren Weckesser <span dir="ltr"><<a href="mailto:warren.weckesser@enthought.com" target="_blank">warren.weckesser@enthought.com</a>></span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Hi all,<br><br>ipython is doing some magic with the output of 'type(a)' (using 0.11.rc1 in EPD):<br><br>In [1]: a = 1<br><br>In [2]: type(a)<br>Out[2]: int<br><br>In [3]: str(type(a))<br>Out[3]: "<type 'int'>"<br>




<br>In [4]: repr(type(a))<br>Out[4]: "<type 'int'>"<br><br>The output in line 2 is nicer, but it makes it appear that the builtin 'type' behaves in a way that it does not.  My attempts (possibly too brief) to find documentation or discussion of this feature have not been fruitful.  Can anyone point me to the relevant docs, or mailing list discussions?  Thanks.<br>


</blockquote><div><br></div></div></div><div>To turn of *all* pretty printing, use %pprint to toggle (as I now see you have discovered)</div><div><br></div><div>output formatting is all handled by the new display system, which is unfortunately not very well documented, but is implemented primarily in <a href="http://ipython.org/ipython-doc/dev/api/generated/IPython.core.formatters.html" target="_blank">IPython.core.formatters</a>.</div>


<div><br></div><div>But here's the gist:</div><div><br></div><div>IPython has a collection of various formatters for various representations of objects (svg, png, html, latex, plaintext, etc.).  Terminal IPython obviously only uses plaintext.  To get the relevant formatter in the terminal:</div>


<div><br></div><div>    formatter = get_ipython().display_formatter.formatters['text/plain']</div><div><br></div><div>And this has a dictionary by *type* of functions to call for given types:</div><div><br></div>

<div>
    formatter.type_printers</div><div><br></div><div>And you can register new type printers with:</div><div><br></div><div>    formatter.for_type(type, myfunc)</div><div><br></div><div>Where myfunc needs to obey the `(obj,p,cycle)` pattern in <a href="http://ipython.org/ipython-doc/dev/api/generated/IPython.lib.pretty.html" target="_blank">IPython.lib.pretty</a>.</div>


<div><br></div><div>If you don't like a particular type's pretty output, you can force it to fallback on repr by just deleting the relevant key from the type_printers dict, or explicitly registering a new printer that writes repr:</div>


<div><br></div><div>    formatter.for_type(type, lambda obj, p, cycle: p.text(repr(obj))</div><div><br></div><div>-MinRK</div><div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">


<font color="#888888">

<br>Warren<br><br>
</font><br>_______________________________________________<br>
IPython-dev mailing list<br>
<a href="mailto:IPython-dev@scipy.org" target="_blank">IPython-dev@scipy.org</a><br>
<a href="http://mail.scipy.org/mailman/listinfo/ipython-dev" target="_blank">http://mail.scipy.org/mailman/listinfo/ipython-dev</a><br>
<br></blockquote></div><br>
</blockquote></div><br>