title: How to replace decorator with method in python class
body: <p>So let's say i have the following code where I am using the get_duration decorator to print out how long a method lasted.</p>
  
  <pre><code>import datetime
  import time
  
  def get_duration(function):
    def wrapper(*args, **kwargs):
      start = datetime.datetime.now()
      print "starting process %s()" %function.__name__
      function(*args, **kwargs)
      end = datetime.datetime.now()
      print "Process lasted: ", end - start
    return wrapper
  
  class Operations(object):
  
    def __init__(self, a, b):
      self.a = a
      self.b = b
  
    @get_duration
    def add(self):
      time.sleep(1)
      print self.a + self.b
  
    @get_duration
    def sub(self):
      time.sleep(1)
      print self.a - self.b
  
  
  my_class = Operations(2, 98)
  my_class.add()
  my_class.sub()
  </code></pre>
  
  <p>Output</p>
  
  <pre><code>&gt;&gt; starting process add()
  &gt;&gt; 100
  &gt;&gt; Process lasted:  0:00:01.000260
  &gt;&gt; starting process sub()
  &gt;&gt; -96
  &gt;&gt; Process lasted:  0:00:01.001161
  </code></pre>
  
  <p>Can i replace this with a class method or something like (pseudo code following):</p>
  
  <pre><code>my_class = Operations(2, 98)
  my_class.add.get_duration #runs add(), prints duration
  my_class.add #runs add() does not print duration
  </code></pre>