Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

3
  • I think your answer is incomplete. The except..as statement will also create a new scope. For example if you put try: raise ValueError('x'); except ValueError as v: pass you cannot access v outside the scope of the except clause Commented Feb 28, 2022 at 16:27
  • 1
    @JohnHenckel That is not a new scope. except deletes its target from its scope when done. The target follows the regular scoping rules, e.g. it can even be declared global and will be deleted from global scope in this case. Demonstrator code. Commented Feb 28, 2022 at 16:47
  • OMG this is strange. Thank you for explaining that to me. Commented Feb 28, 2022 at 16:58