[Python-Dev] PEP 217 - Display Hook for Interactive Use

Guido van Rossum guido@python.org
Sun, 10 Dec 2000 21:24:20 -0500


> Guido wrote:
> > Moshe proposes to add an overridable function sys.displayhook(obj)
> > which will be called by the interpreter for the PRINT_EXPR opcode,
> > instead of hardcoding the behavior.  The default implementation will
> > of course have the current behavior, but this makes it much simpler to
> > experiment with alternatives, e.g. using str() instead of repr() (or
> > to choose between str() and repr() based on the type).

Effbot regurgitates:
> hmm.  instead of patching here and there, what's stopping us
> from doing it the right way?  I'd prefer something like:
> 
>     import code
> 
>     class myCLI(code.InteractiveConsole):
>         def displayhook(self, data):
>             # non-standard display hook
>             print str(data)
> 
>     sys.setcli(myCLI())
> 
> (in other words, why not move the *entire* command line interface
> over to Python code)

Indeed, this is why I've been hesitant to bless Moshe's hack.  I
finally decided to go for it because I don't see this redesign of the
CLI happening anytime soon.  In order to do it right, it would require
a redesign of the parser input handling, which is probably the oldest
code in Python (short of the long integer math, which predates Python
by several years).  The current code module is a hack, alas, and
doesn't always get it right the same way as the *real* CLI does
things.

So, rather than wait forever for the perfect solution, I think it's
okay to settle for less sooner.  "Now is better than never."

--Guido van Rossum (home page: http://www.python.org/~guido/)