Pretty-printing Python interactive output?

Fred L. Drake, Jr. fdrake at acm.org
Wed Sep 8 17:28:16 EDT 1999


François Pinard writes:
 > Is there an easy way or device by which `pprint.pprint' could be called
 > automatically on the expression returned by the interactive interpreter?
 > Best would be able to easily switch this on and off depending on the needs.

  Wow!  I never even thought of this when I wrote that module, but it
seems like a really neat application.  I can certainly see the utility 
of it; in my $PYTHONSTARTUP I do a "from pprint import pprint" to keep 
the function convenient, but being able to make it automatic would be
neat.
  (Thomas Heller probably has the right approach, but I've not looked
at code.InteractiveConsole enough to write the subclass offhand.)
  I think Python should define the interactive loop entirely in Python 
to make it easier to do just this sort of thing.  Once initialization
is complete, if sys.interactive_loop is defined, use that as the
InteractiveConsole object, otherwise create one and use it.  That
would allow easy extension of various aspects of the loop within the
$PYTHONSTARTUP file.


  -Fred

--
Fred L. Drake, Jr.	     <fdrake at acm.org>
Corporation for National Research Initiatives




More information about the Python-list mailing list