On Mon, Jul 7, 2014 at 2:09 AM, Chris Angelico <ros...@gmail.com> 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. -- https://mail.python.org/mailman/listinfo/python-list