> This just reminded me of a question that has been floating around in my > brain for a while. Why doesn't Python support the following fully general > syntax for try-blocks: > > try: > foo() > except blah: > ... > except: > ... > else: > ... > finally: > ... > > I keep having to write: > > try: > try: > foo() > except blah: > ... > except: > ... > else: > ... > finally: > ... At some early point in Python's development, it did support this. I decided to take it out for two reasons: (1) There were so many cases that I couldn't manage to create correct code; (2) the semantics aren't clear: does an exception raised in any of the except clauses jump to the finally clause or not? I'd say it should, but it may not be clear to users (because the except clauses don't apply to each other). It also complicates the bytecode generation: effectively, the compiler has to generate the bytecode equivalent to the second form. The second form makes this explicitly clear. Anyway, I don't think I've seen many too many cases where this would have saved an indentation level. --Guido van Rossum (home page: http://www.python.org/~guido/)
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4