Consider the following:
def f():
a = 2
b = [a + i for i in range(3)]
f()
This works without a problem. I understand (please correct me if I'm wrong), the expression of understanding the context introduces a new scope, but since it is created inside the function (unlike, say, the class), it has access to the surrounding area, including the variable a.
In contrast, if I were to enter debug mode, stop at line 3 above, and then simply manually write the following in the interpreter
>>> b = [a + i for i in range(3)]
I get an error message:
Traceback (most recent call last):
File "<string>", line 293, in runcode
File "<interactive input>", line 1, in <module>
File "<interactive input>", line 1, in <listcomp>
NameError: global name 'a' is not defined
Why is this? When I stop at a given line in debug mode, is this not an area to which I have access to the same as at runtime?
(By the way, I'm using PyScripter)