[Python-Dev] At the interactive port

Guido van Rossum guido@python.org
Mon, 01 May 2000 18:17:17 -0400


> Continuing the recent debate about what is appropriate to the interactive
> prompt printing, and the wide agreement that whatever we decide, users
> might think otherwise, I've written up a patch to have the user control 
> via a function in __builtin__ the way things are printed at the prompt.
> This is not patches@python level stuff for two reasons:
> 
> 1. I'm not sure what to call this function. Currently, I call it
> __print_expr__, but I'm not sure it's a good name
> 
> 2. I haven't yet supplied a default in __builtin__, so the user *must*
> override this. This is unacceptable, of course.
> 
> I'd just like people to tell me if they think this is worth while, and if
> there is anything I missed.

Thanks for bringing this up again.  I think it should be called
sys.displayhook.  The default could be something like

import __builtin__
def displayhook(obj):
    if obj is None:
        return
    __builtin__._ = obj
    sys.stdout.write("%s\n" % repr(obj))

to be nearly 100% compatible with current practice; or use str(obj) to
do what most people would probably prefer.

(Note that you couldn't do "%s\n" % obj because obj might be a tuple.)

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