Take a sample program:
c = 10
def myfunc():
print(c)
myfunc()
This prints 10 as expected, but if we look at another program:
c = 10
def myfunc():
print(c)
c = 1
myfunc()
It says: local variable 'c' referenced before assignment
Here, if the python interpreter is actually going line by line, shouldn't it print 10 before reaching the next line to conclude there's a local variable?
Python has a lexer, tokenizer and parser. Does it go through all the code, parse it before executing them line by line?
Is that why it's able to say there's a local variable down the function?
