Python decorators: howto list wrapped functions by decorator
<p>Is that possible to use python decorators to mark a method, and get it for the later use, if I don't know the name of the wrapped function?</p>

<p>Here is the example, and I don't know the name of method_with_custom_name:</p>

<pre><code>@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)
</code></pre>

<p>So how can I get a list of methods wrapped with <code>@run_this_method</code></p>

<p>If I understand your question correctly (how to decorate a method with an unknown name?) then it is totally possible.</p>

<pre><code>@decorator
def foo(bar):
  pass
</code></pre>

<p>is syntastic sugar for</p>

<pre><code>def foo(bar):
  pass
foo = decorator(foo)
</code></pre>

<p>So in your case you should just do:</p>

<pre><code>method_with_custom_name = run_this_method(method_with_custom_name)
</code></pre>

<p>The example you provided is confusing, though. Why don't you know the name of method_with_custom_name? It is right there. It is called method_with_custom_name. To use the decorated version later, you just call method_with_custom_name.</p>

python python-decorators