open() and EOFError

Ian Kelly ian.g.kelly at
Mon Jul 7 19:25:36 CEST 2014

On Mon, Jul 7, 2014 at 2:09 AM, Chris Angelico <rosuav at> wrote:
> But if the code's more complicated and it's not so easy to split, then
> sure, doesn't seem a problem. It's like spam[foo//bar] and then
> catching either IndexError or ZeroDivisionError - there's no big
> confusion from having two distinct sources of two distinct errors
> handled by two distinct except blocks.

It's good practice to keep your try blocks as narrow as possible in
any case.  One wouldn't normally expect them, but a custom __getitem__
*could* cause a ZeroDivisionError, and a custom __floordiv__ *could*
cause an IndexError.

More information about the Python-list mailing list