Skip to content

Latest commit

 

History

History
24 lines (24 loc) · 470 Bytes

File metadata and controls

24 lines (24 loc) · 470 Bytes

Decorators

  • Python decorator wrap the method
  • Decorators return wrapped method
def elapsed_time(functor):
    def decorated():
        start = time.time()
        functor()
        end = time.time()
        print "Elapsed time: %f" % (end - start)
    return decorated
@elapsed_time
def hello():
    print 'hello'
Result
/usr/bin/python2.7 /home/junha/Documents/develop/python_test/testt.py
123
hello
Elapsed time: 0.000002