I am learning Python with Automate the Boring Stuff with Python. In chapter 3 it talks about functions and scopes etc. It states that a local scope can use global scopes. However, with the example code below, it is not true?
Example Code:
def spam():
print(eggs) #Error!
eggs = 'spam local'
eggs = 'global'
spam()
I understand logically that because eggs has not been assigned a value before we are executing print and it is exactly what the book says. But my question is since, eggs has been assigned a value in the global scope. Why does Python not revert to the global scope to pull variable. Since again, local can call/pull global but not other local, but global can't pull local.
Cheers.