是否可以使用Python装饰器标记一个方法,并在以后使用它,即使我不知道包装函数的名称?
以下是一个例子,我不知道method_with_custom_name方法的名称:
@run_this_method
def method_with_custom_name(my_arg):
return "The args is: " + my_arg
def _init_and_run():
# Here, I want to get and call method_with_custom_name
# but I don't know it's name,
# so the next line isn't valid.
return run_this_method()(my_arg_value)
def run_this_method(m):
def w(my_arg):
_do_some_magic(my_arg, m)
return w
def _do_some_magic(callback_arg, callback):
if some_checks():
callback(callback_arg)
那么我该如何获取使用了@run_this_method
的方法列表呢?