open() and EOFError

Chris Angelico rosuav at gmail.com
Tue Jul 8 06:29:20 EDT 2014


On Tue, Jul 8, 2014 at 7:03 PM, Steven D'Aprano <steve at pearwood.info> wrote:
> 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).

Or you want to have two different signals: empty string means "use the
default", and something else means "exit the application now please".
Very common.

ChrisA



More information about the Python-list mailing list