open() and EOFError

Terry Reedy tjreedy at udel.edu
Tue Jul 8 11:08:44 EDT 2014


On 7/8/2014 10:19 AM, Grant Edwards wrote:
> On 2014-07-07, Gregory Ewing <greg.ewing at canterbury.ac.nz> wrote:
>> Terry Reedy wrote:
>>> Avoid EOFError. Much better, I think, is the somewhat customary
>>>
>>> s = input("Enter something, or hit <return> to exit")
>>> if not s: sys.exit()
>>> else: <process s>
>>
>> I beg to differ -- on Unix, Ctrl-D *is* the customary
>> way to exit from something that's reading from stdin.
>
> Indeed.  Ctrl-D is _the_ canonical way to tell a program that's
> reading stdin that your're done.

Not on Windows.

> I've never run across "hit <return> to exit".
>
>> In any case, you need to be able to handle EOF gracefully if the user
>> uses it.
>


-- 
Terry Jan Reedy




More information about the Python-list mailing list