[Python-ideas] pprint in displayhook

Terry Reedy tjreedy at udel.edu
Fri Sep 27 21:25:15 CEST 2013

On 9/27/2013 12:55 PM, Georg Brandl wrote:
> Am 27.09.2013 12:07, schrieb Serhiy Storchaka:
>> What are you think about using pprint.pprint() to output the result of
>> evaluating an expression entered in an interactive Python session (and
>> in IDLE)?
> This is something users can set in their sitecustomize.py; for various
> reasons people have already mentioned it is not a sensible choice for
> default interactive interpreters.

I agree. The default interpreter cannot be configured on the fly.

> It might be different for IDLE;

It has a menu for both one-time actions and changing defaults. I think a 
menu item and hot-key to re-display the last output object with pprint 
would be a nice little feature. The object remains bound to '_' in the 
user process, so executing "pprint.pprint(_)" should be possible.
(The minor problem is that even if pprint is loaded in sys.modules on 
startup, it might not be in the user global namespace.)

Without seeing a bug-fixed pprint in action, I could not be sure about 
turning on pprint for all output. It is not needed often.

The sitecustomize option would work for a permanent change.

 > I don't know how faithfully it follows
> the interactive interpreter in other regards.

We try have it act the same except where there is a good reason not to.

Terry Jan Reedy

More information about the Python-ideas mailing list