title: Calling a Python Decorator in a class
body: <p>I was wondering if anyone could help me here.
  I have this sample code, trying to test a decorator function that's defined outside, but calling it within a class doesn't seem to work. It simple returns </p>
  
  <blockquote>
    <p>"This is my function"</p>
  </blockquote>
  
  <p>I need it to return with the decorator applied to it as in the code.</p>
  
  <pre><code>  def time_this(original_function):      
          def new_function(*args,**kwargs):
              import datetime                 
              before = datetime.datetime.now()                     
              x = original_function(*args,**kwargs)                
              after = datetime.datetime.now()                      
              print "Elapsed Time = {0}".format(after-before)      
              return x                                             
          return new_function
  
      class TestThis(object):
  
          @time_this
          def myfunction(self):
              return "This is my function"
  
      if __name__ == '__main__':
          print TestThis().myfunction()
  </code></pre>