Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder4.news.weretis.net!rt.uk.eu.org!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!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.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'redirected': 0.07; 'subject:missing': 0.07; 'sys': 0.07; 'data:': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'trailing': 0.09; 'typed': 0.09; 'def': 0.12; 'jan': 0.12; 'anyway': 0.14; 'backspace': 0.16; 'behaviour.': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'reedy': 0.16; 'return,': 0.16; 'subject:python': 0.16; 'wrote:': 0.18; "hasn't": 0.19; 'typing': 0.19; '>>>': 0.22; 'input': 0.22; 'import': 0.22; 'handles': 0.22; 'print': 0.22; 'header:User-Agent:1': 0.23; 'mon,': 0.24; 'equivalent': 0.26; 'header:X-Complaints-To:1': 0.27; 'header:In-Reply-To:1': 0.27; 'function': 0.29; 'am,': 0.29; "doesn't": 0.30; 'gives': 0.31; 'convenience': 0.31; "d'aprano": 0.31; 'steven': 0.31; 'strip': 0.31; 'handled': 0.32; 'level.': 0.33; 'johnson': 0.35; 'no,': 0.35; 'but': 0.35; 'there': 0.35; 'really': 0.36; "didn't": 0.36; 'method': 0.36; 'subject:?': 0.36; 'example,': 0.37; 'to:addr:python-list': 0.38; 'rather': 0.38; 'does': 0.39; 'bad': 0.39; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'even': 0.60; 'read': 0.60; 'lower': 0.61; 'received:173': 0.61; '(that': 0.65; 'worth': 0.66; 'prompt': 0.68; 'console,': 0.84; 'received:fios.verizon.net': 0.84; 'subject:here': 0.84; 'rick': 0.93 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Terry Reedy Subject: Re: buggy python interpretter or am I missing something here? Date: Thu, 30 Jan 2014 04:44:39 -0500 References: <52e600ab$0$29542$862e30e2@ngroups.net> <52e60e69$0$29774$862e30e2@ngroups.net> <52e627bb$0$29811$862e30e2@ngroups.net> <25077ddb-e33d-4c5e-93c8-91d5d079ee8b@googlegroups.com> <0c9b382d-e6e5-490f-93e4-2837b3187cf7@googlegroups.com> <52e6dce7$0$29999$c3e8da3$5496439d@news.astraweb.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Gmane-NNTP-Posting-Host: pool-173-75-254-207.phlapa.fios.verizon.net User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:24.0) Gecko/20100101 Thunderbird/24.2.0 In-Reply-To: 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: 51 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1391075099 news.xs4all.nl 2907 [2001:888:2000:d::a6]:47819 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:64974 On 1/30/2014 12:13 AM, Gregory Ewing wrote: > Steven D'Aprano wrote: >> On Mon, 27 Jan 2014 12:22:22 -0800, Rick Johnson wrote: >> >>> Why do we even need an "input" function anyway if all it is going to do >>> is read from stdin? >> >> That's not all it does. What else it does is print a prompt before reading and to strip off the trailing newline. >> For example, it handles backspacing, so that typing H E L O O >> BACKSPACE BACKSPACE L O gives "HELLO" rather than "HELOO\x7f\x7fO". > > No, it doesn't -- that's handled at a lower level. > Any other method of reading from stdin, as long > as it hasn't been redirected away from the console, > has the same behaviour. > > I typed some backspaces in the input to each of the > following experiments, and they didn't end up in the > data: > > >>> import sys > >>> x = sys.stdin.readline() > HELLO > >>> x > 'HELLO\n' > >>> import os > >>> f = os.fdopen(0) > >>> y = f.readline() > adsxx > >>> y > 'adsxx\n' > > So input() really is a pure convenience function. > (That doesn't mean it's not worth having, though!) It is equivalent to def input(prompt): sys.stdout.write(prompt) return sys.stdin.read()[:-1] There was once an eval around the return, but that was determined to be a bad idea. -- Terry Jan Reedy