open() and EOFError

Chris Angelico rosuav at gmail.com
Mon Jul 7 17:53:19 CEST 2014


On Tue, Jul 8, 2014 at 1:45 AM, Steven D'Aprano
<steve+comp.lang.python at pearwood.info> wrote:
> On Mon, 07 Jul 2014 22:19:20 +1000, Chris Angelico wrote:
>
>> It's possible for input() to raise IOError, if I'm not mistaken;
>> consider redirection, for instance.
>
> What indirection? Do you mean, if built-in input() has been monkey-
> patched? Well, sure, but in that case it could do anything. I'm only
> concerned with the builtins. Otherwise, I have no idea what you mean by
> that.
>
> https://docs.python.org/3/library/functions.html#input

I said redirection, not indirection, and I was thinking of OS-level
changes. If input() is actually reading from some file/device, then
any error that that could raise could come up from reading from stdin.
Imagine if your script is running with input redirected from a file on
a dodgy remote mount, and the far end goes down - at some point,
you'll attempt to read and fail. I'm not sure that you'll see EOF
then; by rights, you ought to see some other error.

ChrisA



More information about the Python-list mailing list