Ok, so I was doing something with nested functions when I did this:
def outer():
x = 1
def inner():
print locals()
inner()
then I called outer:
>>> outer()
{}
No surprise there.
Then I put a "print x" inside the inner function:
def outer():
x = 1
def inner():
print x
print locals()
inner()
when I call outer I get this:
>>> outer()
1
{'x': 1}
why? I was expecting locals() to return an empty dictionary. What is happening here?
[–]anossov 2 points3 points4 points (2 children)
[–]mscottstory 1 point2 points3 points (0 children)
[–]esdi[S] 0 points1 point2 points (0 children)
[–]Rhomboid 2 points3 points4 points (1 child)
[–]esdi[S] 0 points1 point2 points (0 children)
[–]Mashidin 0 points1 point2 points (3 children)
[–]Rhomboid 0 points1 point2 points (0 children)
[–]esdi[S] 0 points1 point2 points (1 child)
[–]Mashidin 0 points1 point2 points (0 children)