Skip to content

Instantly share code, notes, and snippets.

@maple42
Created October 13, 2014 07:23
Show Gist options
  • Save maple42/dc4108a75fb35732af46 to your computer and use it in GitHub Desktop.
Save maple42/dc4108a75fb35732af46 to your computer and use it in GitHub Desktop.
decorator of log
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import functools
def log(func):
@functools.wraps(func)
def wrapper(*args, **kw):
print 'begin call'
func(*args, **kw)
print 'end call'
return wrapper
@log
def now():
print '2014-10-13'
now()
"""
-----------------------------------------------------------------
Result:
begin call
2014-10-13
end call
-----------------------------------------------------------------
"""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment