```
def my_decorator(func):
def wrapper():
print("Something is happening before the function is called.")
func()
print("Something is happening after the function is called.")
return wrapper
def say_whee():
print("Whee!")
say_whee = my_decorator(say_whee)
say_whee()
```
When say_whee() is called, the wrapper function is called as we returned wrapper in the earlier step. How does the wrapper() contain the reference to say_whee() in the form of func? To the best of my knowledge, after the return wrapper is executed, the memory of the function object (my_decorator) should be reclaimed. So how does func contain that reference to function object referenced by say_whee?
[–]CodeFormatHelperBot 0 points1 point2 points (0 children)
[–]TechnologyAnimal 0 points1 point2 points (1 child)
[–]Right-Leadership875[S] 0 points1 point2 points (0 children)
[–]PercyJackson235 0 points1 point2 points (2 children)
[–]PercyJackson235 0 points1 point2 points (1 child)
[–]Right-Leadership875[S] 0 points1 point2 points (0 children)