On Tue, Jul 30, 2019 at 6:04 PM Greg Ewing <greg.ew...@canterbury.ac.nz> wrote:
> Something I don't like about these kinds of proposals is that > the except clause is far removed from the code that it covers, > hurting readability. By the time you get to the end of a big > for-loop or with-statement and see an "except", it's easy to > forget that it isn't attached to an ordinary try-statement. > > I would be happier if there were some way to get the except > clause at the top instead of the bottom, but it's hard to > think of a nice way to do that. > try with open('some_file') as f: except FileNotFoundError: do_something() else: do_something_else(f) was the best I could come up with, and I hate the `except` being indented (but I think a non-indented line right after a : is probably a non-starter). I do think even a clumsy solution is vaguely better than "just make your try: block encompass both the open() and then everything you do with the file after that".
_______________________________________________ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/PYAHYGHB3ZRAOGF6FYU3N4GHY3OF6XXE/ Code of Conduct: http://python.org/psf/codeofconduct/