open() and EOFError

Steven D'Aprano steve at pearwood.info
Tue Jul 8 11:03:02 CEST 2014


On Mon, 07 Jul 2014 14:49:56 -0400, 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>

Under many circumstances, I would do exactly that. But sometimes an empty 
string is valid data, not a signal for special processing (whether 
exiting the application, or something else).


-- 
Steven



More information about the Python-list mailing list