|
|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
×
- def a_new_decorator(a_func):
-
- def wrapTheFunction():
- print("I am doing some boring work before executing a_func()")
-
- a_func()
-
- print("I am doing some boring work after executing a_func()")
-
- return wrapTheFunction
- @a_new_decorator
- def a_function_requiring_decoration():
- """Hey you! Decorate me!"""
- print("I am the function which needs some decoration to "
- "remove my foul smell")
复制代码
以上代码,我不太明白为什么会:
- print(a_function_requiring_decoration.__name__)
- # Output: wrapTheFunction
复制代码
为什么输出的是wrapTheFunction而不是a_new_decorator啊?
在没做修饰符之前
- >>> print(a_function_requiring_decoration.__name__)
- a_function_requiring_decoration
复制代码- >>> print(a_new_decorator.__name__)
- a_new_decorator
复制代码
修饰符不是类似于把一个函数当作参数填入另一个函数么?
那现在a_function_requring_decoration被当作了a_new_decorator的参数,为什么属性__name__返回的却不是a_new_decorator,反而是该函数下的子函数名warpTheFunction啊? |
|