Effective Python 读书笔记 Item 13 Take Advantage of Each Block in try/except/else/finally
分类:
文章
•
2025-01-16 10:56:46
Use try/except/else/finally when you want to do it all in one compound statement.

- The try/finally compound statement lets you run cleanup code regardless of whether exceptions were raised in the try block.
- The else block helps you minimize the amount of code in try blocks and visually distinguish the success case from the try/except blocks.
- An else block can be used to perform additional actions after a successful try block but before common cleanup in a finally block.