buggy python interpretter or am I missing something here?
Gregory Ewing
greg.ewing at canterbury.ac.nz
Thu Jan 30 00:13:54 EST 2014
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
More information about the Python-list
mailing list