title: How to get the name of decorator for function at run time?
body: <p>In the following code the methods(<code>print_a</code> and <code>print_b</code>) of class <code>Test</code>, has been decorated by the two different decorators. </p>
  
  <p>How can I determine that the given method(let say <code>print_a</code>), is decorated with some specific decorator (<code>decorator1</code>) at the runtime?</p>
  
  <p>The easy solution is to change the name of the wrapper function, i.e. changing the <code>wrapper</code> to <code>wrapper1</code> and <code>wrapper2</code> in the decorator method, but the problem with that is I don't have control over that part of the code.</p>
  
  <p>Does python have any reflection API like Java, and could that help me here ?</p>
  
  <pre><code>def my_decorator1(func):
      def wrapper(*args, **kwargs):
          print('I am decorated:1')
          func(*args, **kwargs)
      return wrapper
  
  def my_decorator2(func):
      def wrapper(*args, **kwargs):
          print('I am decorated:2')
          func(*args, **kwargs)
      return wrapper
  
  class Test():
  
      def __init__(self, a=None, b=None):
          self.a = a
          self.b = b
  
      @my_decorator1
      def print_a(self):
          print('Value of a is {}'.format(self.a))
  
      @my_decorator2
      def print_b(self):
          print('Value of b is {}'.format(self.b))
  
  
  if __name__ == '__main__':
  
      d = Test.__dict__
  
      f1 = d.get('print_a')
      f2 = d.get('print_b')
  </code></pre>