Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!xlned.com!feeder5.xlned.com!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'value,': 0.04; 'interpreter': 0.05; 'modify': 0.07; 'sys': 0.07; 'string': 0.09; 'defines': 0.09; 'exception.': 0.09; 'hooks': 0.09; 'raises': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'runs': 0.10; '*before*': 0.16; 'evaluating': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'exception': 0.16; 'do,': 0.16; 'wrote:': 0.18; 'module': 0.19; 'trying': 0.19; 'input': 0.22; 'header:User-Agent:1': 0.23; 'sends': 0.24; 'gets': 0.27; 'header:X-Complaints-To:1': 0.27; 'header:In-Reply-To:1': 0.27; 'am,': 0.29; "d'aprano": 0.31; 'steven': 0.31; 'could': 0.34; 'something': 0.35; 'but': 0.35; 'there': 0.35; 'idle': 0.36; 'two': 0.37; 'to:addr:python-list': 0.38; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'called': 0.40; 'received:173': 0.61; 'details': 0.65; 'prompt': 0.68; 'press': 0.70; 'received:fios.verizon.net': 0.84 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Terry Jan Reedy Subject: Re: Interactive interpreter hooks Date: Mon, 03 Jun 2013 09:03:31 -0400 References: <51ac4bfc$0$11118$c3e8da3@news.astraweb.com> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Gmane-NNTP-Posting-Host: pool-173-75-251-66.phlapa.fios.verizon.net User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:17.0) Gecko/20130509 Thunderbird/17.0.6 In-Reply-To: <51ac4bfc$0$11118$c3e8da3@news.astraweb.com> X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 22 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1370264612 news.xs4all.nl 15996 [2001:888:2000:d::a6]:34244 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:46789 On 6/3/2013 3:55 AM, Steven D'Aprano wrote: > The sys module defines two hooks that are used in the interactive > interpreter: > > * sys.displayhook(value) gets called with the result of evaluating the > line when you press ENTER; > > * sys.excepthook(type, value, traceback) gets called with the details of > the exception when your line raises an exception. > > Is there a way to hook into the interactive interpreter *before* it is > evaluated? That is, if I type "len([])" at the prompt and hit ENTER, I > want a hook that runs before len([]) is evaluated to 0, so that I get the > string "len([])". You have not said what you are actually trying to do, but you could definitely modify Idle to do something with user input before it sends it to the user process.