What is happening under the hood with this code? pythontutor isn't helpful for this.
Some questions: why can ok_then() "see" the variable sure.d? What's the point of naming the variable sure.d if every function in this module can see it?
def ok_then():
print(ok_then.c)
print(sure.d)
def sure():
pass
def set_vals(c,d):
ok_then.c = c
sure.d = d
>>> set_vals(3, 4)
>>> ok_then
3
4
Finally, why does this error? Something is happening with the ok_then.c and sure.d from a scope perspective but I'm not clear exactly what.
def ok_then():
print(a)
print(b)
def sure():
pass
def set_vals(c,d):
a = c
b = d
>>> set_vals(3,4)
>>> ok_then()
Traceback (most recent call last):
File "<pyshell#9>", line 1, in <module>
ok_then()
File "C:/Users/test_set_vals.py", line 2, in ok_then
print(a)
NameError: name 'a' is not defined
__slots__) has__dict__- so any arbitrary member may be assigned to any object.sure.dis the same as the local variabledinside ofsure(). It's not.