PEP 217 - Display Hook for Interactive Use

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). Moshe has asked me to pronounce on this PEP. I've thought about it, and I'm now all for it. Moshe (or anyone else), please submit a patch to SF that shows the complete implementation! --Guido van Rossum (home page: http://www.python.org/~guido/)

Guido wrote:
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>

Effbot regurgitates:
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/)

Guido wrote:
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>

Effbot regurgitates:
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/)
participants (2)
-
Fredrik Lundh
-
Guido van Rossum