[IPython-dev] Output of, e.g., type(a)

Robert Kern robert.kern at gmail.com
Sat Oct 22 14:36:56 EDT 2011


On 10/22/11 6:58 PM, Warren Weckesser wrote:
>
>
> On Sat, Oct 22, 2011 at 12:49 PM, Warren Weckesser
> <warren.weckesser at enthought.com <mailto:warren.weckesser at enthought.com>> wrote:
>
>     Hi all,
>
>     ipython is doing some magic with the output of 'type(a)' (using 0.11.rc1 in
>     EPD):
>
>     In [1]: a = 1
>
>     In [2]: type(a)
>     Out[2]: int
>
>     In [3]: str(type(a))
>     Out[3]: "<type 'int'>"
>
>     In [4]: repr(type(a))
>     Out[4]: "<type 'int'>"
>
>     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.
>
>
>
> Of course, three minutes after sending that email, I find the '%pprint' command
> for toggling pretty-printing.  That's enough to answer my question.

The default pretty-printers are defined starting here:

   https://github.com/ipython/ipython/blob/master/IPython/lib/pretty.py#L463

These were the defaults for the upstream, third-party pretty.py (with a just a 
bug-fix for the re objects, IIRC). I happen to like this one, but if there is a 
consensus that it is more confusing than pretty, I'm happy to consider changing it.

-- 
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
  that is made terrible by our own mad attempt to interpret it as though it had
  an underlying truth."
   -- Umberto Eco




More information about the IPython-dev mailing list