Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!news-1.dfn.de!news.dfn.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: Gregory Ewing Newsgroups: comp.lang.python Subject: Re: buggy python interpretter or am I missing something here? Date: Thu, 30 Jan 2014 18:13:54 +1300 Lines: 37 Message-ID: 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=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Trace: individual.net x/QF4gt1WQBz0Mt3LOOO/QBp9PrHak8QXTT0rL2H+A+KZ7vNMC Cancel-Lock: sha1:Gq7lWXDaZf/MwkPKBzE/K+dYDvI= User-Agent: Mozilla Thunderbird 1.0.5 (Macintosh/20050711) X-Accept-Language: en-us, en In-Reply-To: <52e6dce7$0$29999$c3e8da3$5496439d@news.astraweb.com> Xref: csiph.com comp.lang.python:64965 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. > > 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!) -- Greg