Created
October 13, 2014 07:23
-
-
Save maple42/dc4108a75fb35732af46 to your computer and use it in GitHub Desktop.
decorator of log
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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