[Python-ideas] pprint in displayhook

Robert Kern robert.kern at gmail.com
Wed Oct 2 17:31:58 CEST 2013


On 2013-10-02 01:56, Steven D'Aprano wrote:
> On Sun, Sep 29, 2013 at 11:38:30PM +0300, Serhiy Storchaka wrote:
>> 28.09.13 07:17, Raymond Hettinger написав(ла):
>>> This might be a reasonable idea if pprint were in better shape.
>>> I think substantial work needs to be done on it, before it would
>>> be worthy of becoming the default method of display.
>>
>> What should be changed in pprint?
>
> I would like to see pprint be smarter about printing lists and dicts. At
> the moment, a long list is either printed all on one line, like the
> default display, or one item per line. This can end up as one long,
> narrow column, which is worse than the default. I'd like to see it be
> smarter about using multiple columns.
>
> E.g. pprint([1, 2, 3, ... 1000])
>
> rather than this:
>
> [1,
>   2,
>   3,
>   ...
>   998,
>   999,
>   1000]
>
> something like this:
>
> [1,    2,    3,    4,    5,    6,    7,    8,    9,   10,
>   ...
>   991,  992,  993,  994,  995,  996,  997,  998,  999, 1000]

As someone who has used pretty-printing as their default displayhook for a 
decade now via IPython, I have to say that this case happens much less often 
than one might expect. It *is* irritating the rare times it does come up, but 
less so than what I expect we would see from the false positives of a more 
intelligent algorithm. But I withhold final judgement until I see the actual 
results of such an algorithm.

-- 
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 Python-ideas mailing list