Movatterモバイル変換


[0]ホーム

URL:


Following system colour schemeSelected dark colour schemeSelected light colour scheme

Python Enhancement Proposals

PEP 217 – Display Hook for Interactive Use

Author:
Moshe Zadka <moshez at zadka.site.co.il>
Status:
Final
Type:
Standards Track
Created:
31-Jul-2000
Python-Version:
2.1
Post-History:


Table of Contents

Abstract

Python’s interactive mode is one of the implementation’s greatstrengths – being able to write expressions on the command lineand get back a meaningful output. However, the output functioncannot be all things to all people, and the current outputfunction too often falls short of this goal. This PEP describes away to provides alternatives to the built-in display function inPython, so users will have control over the output from theinteractive interpreter.

Interface

The current Python solution has worked for many users, and thisshould not break it. Therefore, in the default configuration,nothing will change in the REPL loop. To change the way theinterpreter prints interactively entered expressions, userswill have to rebindsys.displayhook to a callable object.The result of calling this object with the result of theinteractively entered expression should be print-able,and this is what will be printed onsys.stdout.

Solution

The bytecodePRINT_EXPR will callsys.displayhook(POP()).Adisplayhook() will be added to the sys builtin module, which isequivalent to:

import __builtin__def displayhook(o):    if o is None:        return    __builtin__._ = None    print `o`    __builtin__._ = o

Jython Issues

The methodPy.printResult will be similarly changed.


Source:https://github.com/python/peps/blob/main/peps/pep-0217.rst

Last modified:2025-02-01 08:55:40 GMT


[8]ページ先頭

©2009-2025 Movatter.jp