NOTE: This question is not directly related to decorators, but rather the concept of them. It is NOT related to these 2 questions:
- What is decorator with "@" above a function in Python? [duplicate] (7 answers)
- How do I make function decorators and chain them together? (19 answers)
MY QUESTION: I'm currently experimenting with inner functions to get a good grasp of python decorators.
With this code below, I am able to successfully print "sup" through the wrapper function, even though I didnt explicitly call it.
def my_decorator(test):
def wrapper():
print(test)
return wrapper
hello = my_decorator("sup")
hello()
This however, doesnt work if I do any of the following
- remove
return wrapper
- directly call
my_decorator("sup")
without passing it into the hello function
correspondingly, I have 2 questions:
- does
return wrapper
automatically call the wrapper function? - What's the difference between using a reference function like hello, and directly calling the my_decorator function?