你
返回
wrapper
并分配给
say_wee
:
say_whee = my_decorator(say_whee)
所以这里叫:
say_whee()
自己看看:
>>> 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
<function my_decorator.<locals>.wrapper at 0x1040d89d8>
>>> say_whee.__name__
'wrapper'