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

Fredrik Lundh fredrik@effbot.org
Mon, 11 Dec 2000 01:16:25 +0100


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).

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)

</F>