2000-07-31 16:15:14 -04:00
|
|
|
|
PEP: 217
|
|
|
|
|
Title: Display Hook for Interactive Use
|
|
|
|
|
Version: $Revision$
|
2006-03-23 15:13:19 -05:00
|
|
|
|
Last-Modified: $Date$
|
2000-11-02 03:05:38 -05:00
|
|
|
|
Author: peps@zadka.site.co.il (Moshe Zadka)
|
2001-01-11 00:46:24 -05:00
|
|
|
|
Status: Final
|
2000-08-23 01:51:13 -04:00
|
|
|
|
Type: Standards Track
|
|
|
|
|
Python-Version: 2.1
|
2000-07-31 16:15:14 -04:00
|
|
|
|
Created: 31-Jul-2000
|
|
|
|
|
Post-History:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Abstract
|
|
|
|
|
|
|
|
|
|
Python's interactive mode is one of the implementation's great
|
|
|
|
|
strengths -- being able to write expressions on the command line
|
|
|
|
|
and get back a meaningful output. However, the output function
|
|
|
|
|
cannot be all things to all people, and the current output
|
|
|
|
|
function too often falls short of this goal. This PEP describes a
|
|
|
|
|
way to provides alternatives to the built-in display function in
|
|
|
|
|
Python, so users will have control over the output from the
|
|
|
|
|
interactive interpreter.
|
|
|
|
|
|
2000-11-02 18:53:51 -05:00
|
|
|
|
Interface
|
|
|
|
|
|
|
|
|
|
The current Python solution has worked for many users, and this
|
|
|
|
|
should not break it. Therefore, in the default configuration,
|
|
|
|
|
nothing will change in the REPL loop. To change the way the
|
|
|
|
|
interpreter prints interactively entered expressions, users
|
|
|
|
|
will have to rebind sys.displayhook to a callable object.
|
|
|
|
|
The result of calling this object with the result of the
|
|
|
|
|
interactively entered expression should be print-able,
|
|
|
|
|
and this is what will be printed on sys.stdout.
|
|
|
|
|
|
2000-11-02 03:05:38 -05:00
|
|
|
|
Solution
|
|
|
|
|
|
|
|
|
|
The bytecode PRINT_EXPR will call sys.displayhook(POP())
|
|
|
|
|
A displayhook() will be added to the sys builtin module, which is
|
|
|
|
|
equivalent to
|
|
|
|
|
|
|
|
|
|
import __builtin__
|
|
|
|
|
def displayhook(o):
|
|
|
|
|
if o is None:
|
|
|
|
|
return
|
2000-11-02 18:53:51 -05:00
|
|
|
|
__builtin__._ = None
|
|
|
|
|
print `o`
|
2000-11-02 03:05:38 -05:00
|
|
|
|
__builtin__._ = o
|
|
|
|
|
|
|
|
|
|
Jython Issues
|
|
|
|
|
|
2000-11-02 18:53:51 -05:00
|
|
|
|
The method Py.printResult will be similarily changed.
|
2000-07-31 16:15:14 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Local Variables:
|
|
|
|
|
mode: indented-text
|
|
|
|
|
indent-tabs-mode: nil
|
|
|
|
|
End:
|