why are *two* ctrl-D's needed with readline()

Wilhelm Fitzpatrick rafial at well.com
Fri Oct 5 12:04:38 EDT 2001


I was writing a little python script using

for line in sys.stdin.readlines() :

to iterate through input, and I noticed that I had to press ctrl-D
TWICE to terminate input.  This same behavior appears whether I am in
interactive mode or running a script, and I confirmed the same
behavior using both python 2.0.1 and 1.5.2.

Interestingly, enough

for line in sys.stdin.read().splitlines() :

terminates on the first ctrl-D (as I would expect).

Why the strange behavior for readlines()?  is this an implemenation
limitation?  A bug?  A feature that I do not properly understand?  I
searched the docs and the mailing list archives but I could not find
enlightenment.





More information about the Python-list mailing list