I am trying to understand how python stores and accesses its functions as objects . For example take the following code-
def make_pretty(func):
def inner():
print("I got decorated")
func()
return func
return inner
def ordinary():
print("I am ordinary 2")
ordinary()
pretty=make_pretty(ordinary)
pretty()
When executed , pretty() returns
I got decorated
I am ordinary 2
<function __main__.ordinary()>
which seems to imply that the ordinary() function passed to make_pretty() is accessed as in the main scope, and as dir(pretty) doesn't show ordinary (Please correct me if i am wrong). Now if I run this code after this
def ordinary():
print("I am ordinary 3")
pretty()
I still get the same output as before , even though I have the changed the global definition of ordinary , i.e. pretty still is considering the previous definition of ordinary even though I have redefined ordinary and the func in pretty is referring to global ordinary
Why is this so? I clearly am wrong somewhere but I don't understand where. Some insight would be appreciated. Thanks