[Python-ideas] python3: subtle change to new input()
mark at qtrac.eu
Wed Nov 14 17:37:56 CET 2007
On 2007-11-14, Guido van Rossum wrote:
> On Nov 14, 2007 6:00 AM, Mark Summerfield <mark at qtrac.eu> wrote:
> > On 2007-11-14, Georg Brandl wrote:
> > > Mark Summerfield schrieb:
> > > > Hi,
> > > >
> > > > In Python 3, input() returns an empty string in two situations: blank
> > > > lines and EOF.
> > >
> > > Could this be a platform issue? Here, on Linux, input() raises EOFError
> > > on EOF.
> > Sorry, you're quite right...
> Mark, did it return "" on your platform? Then please file a bug. I
> can't quite tell if that's the case or if you simply misread the docs.
It isn't a Python 3 bug. I confused myself with my tests. Sorry!
And the docs are perfectly okay... well, apart from "stripping a
trailing newline". On Unices that's fine but I don't know if Windows
consoles actually send \r\n or whatever, in which case, assuming input()
does the right cross-platform thing, maybe "stripping the trailing line
termination character(s)" would be more accurate.
(What went wrong: My little program worked fine when I used it
interactively. But then I ran it using a file of data redirected from
stdin, that didn't produce an EOFError. But the reason was that my test
file had a blank line in it, so the program correctly broke out of the
while loop at that point and stopped reading, so never reached EOF. Once
I removed the blank line the program correctly terminated with an
Mark Summerfield, Qtrac Ltd., www.qtrac.eu
More information about the Python-ideas