scoping

"except Foo as bar" causes "bar" to be removed from scope

"except Foo as bar" causes "bar" to be removed from scope Question: Given the following code: msg = “test” try: “a”[1] except IndexError as msg: print(“Error happened”) print(msg) Can somebody explain why this causes the following output in Python 3? Error happened Traceback (most recent call last): File “test.py”, line 6, in <module> print(msg) NameError: …

Total answers: 3

Python class scoping rules

Python class scoping rules Question: EDIT: Looks like this is a very old “bug” or, actually, feature. See, e.g., this mail I am trying to understand the Python scoping rules. More precisely, I thought that I understand them but then I found this code here: x = “xtop” y = “ytop” def func(): x = …

Total answers: 2