This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Tutorial should mention about variable scope in try/except/finally
Type: enhancement Stage:
Components: Documentation Versions: Python 3.9
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: docs@python Nosy List: deekox, docs@python, eric.araujo
Priority: normal Keywords:

Created on 2021-03-10 05:08 by deekox, last changed 2022-04-11 14:59 by admin.

Messages (2)
msg388407 - (view) Author: Marek M (deekox) Date: 2021-03-10 05:08
It can be helpful to mention that variables defined in try block are visible in except/finally block as well. I did not find this info in Python tutorial and for me (having C++ background) this is quite unexpected feature.
msg388547 - (view) Author: Éric Araujo (eric.araujo) * (Python committer) Date: 2021-03-12 19:47
The only blocks that create scopes are modules, class and functions.
if, try, with, for, while, etc are blocks but not new scopes.

For the tutorial it could be nice to have an explicit mention and example of this.
History
Date User Action Args
2022-04-11 14:59:42adminsetgithub: 87624
2021-03-12 19:47:11eric.araujosetnosy: + eric.araujo
messages: + msg388547
2021-03-10 05:08:31deekoxcreate