error handling when opening files

Chris Angelico rosuav at
Tue Jul 8 07:25:26 CEST 2014

On Tue, Jul 8, 2014 at 9:49 AM, Alex Burke <alexjeffburke at> wrote:
> The reason I preferred the second was in addition to catching the
> IOError when attempting the open() if the file does not exist I
> thought I was accounting for the possibility en error occurs while
> reading data out of the file.

If that's what you're expecting, then your message is wrong, because
you say "file never opened" - but you possibly DID open it, and maybe
read something from it. The choice between the two forms should be
based on whether you want to distinguish between errors on opening and
errors on reading, or conflate them as "file unreadable". There are
times and places for each style.


More information about the Python-list mailing list