37,720
社区成员
发帖
与我相关
我的任务
分享
import copy
def my_shiny_new_decorator(a_function_to_decorate):
global original_function
original_function = copy.copy(a_function_to_decorate)
def the_wrapper_around_the_original_function():
print("Before the function runs")
a_function_to_decorate()
print("After the function runs")
return the_wrapper_around_the_original_function
def restore_func(a_function_to_restore):
a_function_to_restore = original_function
return a_function_to_restore
@my_shiny_new_decorator
def another_stand_alone_function():
print("Leave me alone")
another_stand_alone_function()
another_stand_alone_function = original_function
another_stand_alone_function() # 这里输如下
# Before the function runs
# Leave me alone
# After the function runs
# Leave me alone